r/JavaFX • • Mar 21 '25

Tutorial New Article: Should You Use FXML?

This topic has come up here a few times recently, and I've had a few DM's about it too. I had the feeling that I must have covered this topic over and over, but when I looked back through my articles I only found one from around 2021 that talked about FXML and MVC.

This ended up being a longer article than I anticipated, and Jekyll says it's an even longer read because I included 462 lines of FXML that I scooped off GitHub to make a point about how "intuitively readable" it isn't. But it's still long.

So, if you want the TDLR, here it is:

Most of the wondrous claims about how FXML instantly improves your various aspects of your application design are just rubbish - and I take some time to prove it for a few of them. It's clear that even some of the claims made in the Oracle tutorials are just wrong.

What you do get from FXML is the ability to SceneBuilder, and that should be the sole motivation for your decision to use FXML - which is actually backwards: SceneBuilder is the only motivation to use FXML. I'm also fairly certain that SceneBuilder isn't a good beginners' tool either.

The article explores how it's tougher to employ a library of custom methods and classes to simplify layout creation with FXML.

Finally, I take a look how to properly integrate FXML with a framework. In this case I use MVCI (because it's better, of course). This is probably the most important section for any of you determined to use FXML but still want to architect your applications properly, because 99% of the tutorials out there on the web just get this wrong.

If any of that intrigues you, and you want to know more, then have a look at the article:

https://www.pragmaticcoding.ca/javafx/fxml-or-not

18 Upvotes

24 comments sorted by

View all comments

Show parent comment

1

u/TenYearsOfLurking Mar 24 '25

you make some fair points, and I will only respond to the last one now due to time constraints.

I will repeat myself now: virtually everyone touched html at some point, I personally come from a web dev background. Writing markup code to structure the layout feels natural to me and tool support in IDEA for that is great. So I was a beginner, it helped me onboarding and I am confident that my fxml code was better than my controller code. It complements my workflow from webdev: layout the structure then wire everything up.

Even if you oppose fxml, I hope you can see that it's existence is important for onboarding. Either for ppl used to writing markup code for UIs (again virtually every UI tech has such a possibility) or using tools like scenebuilder (same).

Is a javafx ninja like yourself more productive without? I don't doubt that at all. Do UI tools generate weird code sometimes? you bet! Is being close to a webdev workflow a boon for the technology? I'd argue YES