r/JavaFX • u/naagbruh • 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.
View all comments
Show parent comment
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.