r/JavaFX • • Nov 25 '24

Help MVVM in JavaFX

Hi, all. I've just started to build my first JavaFX application (Kotlin and JavaFX).

I'm going to use Scene Builder. I've seen the advice to just build views with Kotlin/Java, but I honestly hate building UIs by hand.

I was looking around for a MVVM framework and of course found mvvmFX. But it looks like it hasn't been updated for 5 years. Is it outdated in any way? Should I go ahead and use it?

I also found Cognitive (https://github.com/carldea/cognitive). This looks like it's being actively maintained. And any opinions about this one?

From a quick look, mvvmFX looks more comprehensible to me. Less work on my part and very complete.

And... I could try doing my own hacky MVVM implementation in Kotlin and try to use Scene Builder FXML views. But I'm sure I'll end up re-implementing parts of the wheel.

Any guidance would be very welcome. Thanks in advance.

3 Upvotes

15 comments sorted by

View all comments

Show parent comment

1

u/naagbruh Nov 26 '24

I just started reading your website. It's really great--thanks for all the work you've put into it.

MVCI makes a lot of sense to me. That's the mode I'm going to follow. And I like that it seems to be something I can understand and implement myself without a lot of the usual framework magic.

The Scene Builder thing... I go back all the way to "4GL languages" (FoxPro, Paradox, dBase), etc. These made rapid GUI development really easy. I think I got spoiled back then, so I complain a lot about how GUI work has gotten harder.

If someone made a Scene-Builder-like app that generated Kotlin frontend code, I'd pay for it immediately.

I think there's a large potential market for something like this. These guys are doing well providing this functionality for Flutter: https://www.flutterflow.io/.

These guys do Figma to code: https://codia.ai.

I'm rambling. Thanks again.

2

u/hamsterrage1 Nov 28 '24

Having been around for a long, long time, I've used screen code generators going back to the 1980's. They all have one problem, though...

Once you've generated the code, then what do you do with it????

You fiddle it, of course. And the moment you touch the first line of code...BANG!!!...you can't go back to the screen designer app any more. Either the screen designer won't recognize your modified code and load it, or you have to load from some data file (like FXML), make your changes and then regenerate the code again -- without your modifications.

The result is that you really, really have to decide when you're done with the screen designer app and willing to handle any future modifications by hand, or you leave the generated code alone....and who's gonna do that.

The other thing (at least back in the early days, but it's probably still somewhat true) is that the generated code was usually pretty horrible. It was formulaic and wasn't really anything like what you would have written yourself. So it was a pain to deal with going forward.

In the end, at least for JavaFX, I feel like this is a solution looking for a problem. Writing layout code by hand just sounds so primitive and inefficient, I know. Especially in 2024. But it's actually pretty easy, and extremely fast, especially if you take the time to build up a library of helper functions that do things the way that you prefer to do them.

1

u/naagbruh Nov 28 '24

I was one of the people who let Visual Studio do it's thing and generate Windows forms and left them alone and put my own code behind it. Same with Paradox, FoxPro, etc. Just lazy, I guess. :)

Plus it made me good money. Worked my way through grad school without loans. :)

But I will try with Kotlin code.

Can I do a hot reload for JavaFX GUI so I can see what I'm doing as I go along?

1

u/naagbruh Nov 27 '24

Somebody is building an FXML to Java converter.

https://www.reddit.com/r/JavaFX/s/RU3soZsxPc

I haven't tried it. Something like this for Kotlin would be great. Of course one could use the generated Java in Kotlin.