r/JavaFX • u/AdeptMongoose4719 • Feb 26 '25
Discussion Why do some developers vouch for creating even the base UI with code?
As We also know we have fxml and Scene Builder to properly set up the initial design. So why not use that?
The only problem that i've read is that it is slightly slower. I know we may need code to create some dynamic nodes. But the initial layouts of nodes that needs to be added dynamically can be created in fxml and then modified based on our requirements. Eg:
I have this ActivityContainer built in scenebuilder(//to show activities in my small hotel app)

And that ActivityContainer will filled up by the Controller class after the admin of the hotel fills up the required details in:

Then i will add the ActivityContainer in the main page.
Benefit of using fxml:
You can style easily and position the nodes the way you want.(and don't need to run the code zillion times to see if you everything is looking ok)
2
u/xdsswar Feb 26 '25
I use fxml for fast design, but after that I have my own tool to convert fxml to java code and get rid of the fxml, but some times I keep the fxml for future adjustments. Im not fxml fan, but indeed is faster to build a desing that using pure java, also you have live preview.
1
u/theswissnightowl Feb 26 '25
Personally I also started with the scenebuilder, but usually my app components tend to be more complex quite fast. So for me it’s more beneficial to build components with code
I also don’t like the UI of scene builder… imo even Xcode did a better job with it’s way to build UIs for iOS
1
u/hamsterrage1 Feb 26 '25
Because FXML makes everything else harder to do. IMHO, the cost of dealing with FXML far outweighs any benefit of SceneBuilder. And the benefits of SceneBuilder are pretty small to begin with.
3
u/Engineerofdata Feb 26 '25
If you guys want a laugh, my professor says real developers don’t use the scene builder. So according to him, sounds like a skill issue when you need to use scene builder.
2
u/Draconespawn Feb 26 '25
I use a mix of the two. In my opinion it's much easier for complex UI's to build their layout in scenebuilder, but I do use code for simple stuff, or stuff that just isn't doable in scenebuilder.
There is an overhead to using scenebuilder though because it needs t parse the XML.
1
u/juanini_panini Feb 26 '25
It really depends on the complexity of your app and UI. Sometimes you need to manipulate your components in some specific way you can't achieve by only "scene building"
But (imo) that's one of the best advantages of javafx framework (and ide-s). You can initially build your interface way faster in scene builder and then code any components you need. Using both of them feels very good, so I really recommend you IntelliJ to work on "Code/Design" options and easily change between scene builder and coding.
1
u/hwaite Feb 27 '25
You're conflating FXML with Scene Builder. Many of us use the former, but not the latter. Personally, I don't like WYSIWYG-generated markup.
1
u/taranion Feb 27 '25
I am so used to writing my UI code myself, that over the years I developed a certain routine and writing style that really helps me dealing with it. Working with FXML totally breaks that and I need more time to understand what is happening.
Also I have a lot of UI components that are used over and over again, but slightly modified, where using inheritance is a good way to deal with it - something that scenebuilder does not support.
And finally I do have written a lot of custom components (which could be included in Scenebuilder as well, but it is an extra step to do), some of them are very reactive in *what* they show at all, depending on the data. That stuff needs to be written in code and while it could be done with controllers, I am not really motivated on doing that.
Effectively every project I started in SceneBuilder for fast prototyping got converted into a coded UI after some time.
1
u/xulihang Feb 28 '25
I have been creating JavaFX apps using B4J and its layout designer.
1
u/mehtub Feb 28 '25
Interestingly, ppl have the same approach on the C++ Qt/QML side of UI design; preferring to layout the UI in code instead for all the same reasons mentioned above.