2

I am so-so with Swing and just starting to learn JavaFX. I went over a few answers on SO with regards to which one to use and I still can not make up my mind.

Is it possible to get the best of both the worlds ??

Like, use JavaFX with I want to give some visually appealing graphics and add some Swing to JavaFX when I want to ?

3 Answers 3

3

You can use JavaFX in Swing applications via the JFXPanel control. See the SwingInterOp sample. You can also utilize JavaFX from inside sophisticated Swing based platforms such as NetBeans RCP.

A current limitation of JavaFX/Swing integration is that you can embed JavaFX components in a Swing application, but not Swing components in a JavaFX application. RT-12100 Swing in JavaFX embedding support is currently scheduled for Java 8.

If you have a green field new application to develop, I'd advise choosing one technology or the other and sticking with that or at least keeping the integration points localized and few and far between. Both frameworks are large and take time to learn, plus you will avoid any integration headaches such as needing to take care that Swing processing is done on the Swing Event Dispatch thread and JavaFX processing is done on the JavaFX Application Thread.

JavaFX also integrates with SWT and that integration is currently simpler than the JavaFX/Swing integration (because there is only a single GUI thread to worry about).

Here is a screenshot of JavaFX/Swing interop sample from Oracle:

swinginterop image

I went over a few answers on SO with regards to which one to use and I still can not make up my mind.

Rather than doing that, I'd advise picking a small application and implementing it from scratch in Swing and JavaFX and seeing which you prefer. It's time better spent as there is no substitute for hands on experience - then, if you still have questions (hopefully more specific and targeted), come back to StackOverflow to research or ask them.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for the answer. For swanky graphics done easily, I guess JavaFX is better but for the normal UIs I guess Swing would suffice :)
2

It depends on your motivation for learning them. If you're looking primarily to boost your CV in the near future and become attractive to businesses, then (for the moment at least) there's many more applications out there written in Swing than JavaFX, purely because the latter is a much newer toolkit.

However, if you're thinking more long term or just want the best tool for the job, personally I find JavaFX to offer more flexibility, be much easier to code in an aesthetically pleasing way, and easier to learn as well (the API behind it is just much nicer.) The only thing against it at the moment is that there's some features that I'd really like to be included, but aren't yet (again, naturally this is what you get by going for the newer toolkit.)

I'd also advise against mixing the two. I'm currently involved in two projects using JavaFX, one entirely JavaFX based and the other a mixture of FX and swing. The latter is much more fiddly to maintain, primarily because of the difference in dispatch threading.

1 Comment

See, that's why really love this place ---- honest opinions :)
2

As a previous poster stated, you can use JavaFX in Swing applications now. But since Oracle has declared that JavaFX is the future of the desktop for Java, why not just learn it. I've tried to keep current on both and it's a chore. I'm planning on focusing on JavaFX exclusively in the future -- less chance of confusing myself.

That said, JavaFX still doesn't seem to be a full-fledged member of the JDK, especially if used in conjunction with other languages, like Clojure for example. Depending on the JavaFX version, there are different machinations to go through to pull it into build tools. But that situation is getting better with each release.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.