Swing vs JavaFx for desktop applications [closed]
Asked Answered
I

6

211

I have a very big program that is currently using SWT. The program can be run on both Windows, Mac and Linux, and it is a big desktop application with many elements. Now SWT being somewhat old I would like to switch to either Swing or JavaFX. And I would like to hear your thoughts on three things.

My main concern is what will be better for a desktop GUI application? (I looked online and a lot of people suggest that JavaFX is just as good as Swing, but I didn't see many valid arguments except simple opinion flame wars). It has to work on both Windows, Mac and some popular Linux distributions.

  • What will be cleaner and easier to maintain?

  • and what will be faster to build from scratch?

I am using MVC methology in my application, if that is of any help.

Inhambane answered 22/5, 2013 at 14:49 Comment(8)
JavaFX is good is you're starting from scratch. Also because JavaFX is officially replacing Swing as Oracle's UI library for Java. That does not mean Swing is done away with. It just means JavaFX will get a lot more attention in every release. With that said, there are a million and a half questions on this topic on SO and elsewhere on Google already.Evergreen
#10588213 I also mentioned Google. Plenty out there already.Evergreen
Ok so suggestion really seems to be fx then, I will keep this open, but will accept an answer I guess. Thanks for the links.Inhambane
Here is a quick summary of JavaFX though any of SWT, Swing or JavaFX will work to produce a desktop application.Progressive
No one has mentioned it, but JavaFX does not compile or run on certain architectures deemed "servers" by Oracle (e.g. Solaris), because of the missing "jfxrt.jar" support.Single
possible duplicate of Java GUI frameworks. What to choose? Swing, SWT, AWT, SwingX, JGoodies, JavaFX, Apache Pivot?Deportation
JavaFX Designer is slow, too slow. I'm not able to work on my design, i'm forced to write the design since Netbeans freeze whenever i add a button with the designer. Swing does good though, never had a problem with that.Mesh
After some months with JavaFX, when i look back to my Swing projects from school, they seem really outdated. Properties & Bindings are way more intuitive than listeners were in Swing. The lack of MDI support hasn't been an issue for me al least, i prefer tabs. Styling with css is way more managable than setting and overriding methods.Sekofski
S
165

What will be cleaner and easier to maintain?

All things being equal, probably JavaFX - the API is much more consistent across components. However, this depends much more on how the code is written rather than what library is used to write it.

And what will be faster to build from scratch?

Highly dependent on what you're building. Swing has more components around for it (3rd party as well as built in) and not all of them have made their way to the newer JavaFX platform yet, so there may be a certain amount of re-inventing the wheel if you need something a bit custom. On the other hand, if you want to do transitions / animations / video stuff then this is orders of magnitude easier in FX.

One other thing to bear in mind is (perhaps) look and feel. If you absolutely must have the default system look and feel, then JavaFX (at present) can't provide this. Not a big must have for me (I prefer the default FX look anyway) but I'm aware some policies mandate a restriction to system styles.

Personally, I see JavaFX as the "up and coming" UI library that's not quite there yet (but more than usable), and Swing as the borderline-legacy UI library that's fully featured and supported for the moment, but probably won't be so much in the years to come (and therefore chances are FX will overtake it at some point.)

Scoop answered 22/5, 2013 at 15:0 Comment(1)
I believe these points all apply to the .NET world as well in the desktop GUI world, where Windows Presentation Foundation is the modern approach aiming to replace the old Windows Forms, so it's theoretically better in all aspects except it won't (yet? but it's been years) support the native common controls / shell look you've come to expect such as a simple file dialog / directory browser / tree view control.Genesisgenet
B
91

As stated by Oracle, JavaFX is the next step in their Java based rich client strategy. Accordingly, this is what I recommend for your situation:

What would be easier and cleaner to maintain

  • JavaFX has introduced several improvements over Swing, such as, possibility to markup UIs with FXML, and theming with CSS. It has great potential to write a modular, clean & maintainable code.

What would be faster to build from scratch

  • This is highly dependent on your skills and the tools you use.
    • For swing, various IDEs offer tools for rapid development. The best I personally found is the GUI builder in NetBeans.
    • JavaFX has support from various IDEs as well, though not as mature as the support Swing has at the moment. However, its support for markup in FXML & CSS make GUI development on JavaFX intuitive.

MVC Pattern Support

  • JavaFX is very friendly with MVC pattern, and you can cleanly separate your work as: presentation (FXML, CSS), models(Java, domain objects) and logic(Java).
  • IMHO, the MVC support in Swing isn't very appealing. The flow you'll see across various components lacks consistency.

For more info, please take a look these FAQ post by Oracle regarding JavaFX here.

Bobodioulasso answered 17/2, 2014 at 20:13 Comment(0)
S
19

No one has mentioned it, but JavaFX does not compile or run on certain architectures deemed "servers" by Oracle (e.g. Solaris), because of the missing "jfxrt.jar" support. Stick with SWT, until further notice.

Single answered 4/4, 2014 at 1:42 Comment(1)
@Inhambane specially asks for something to build a desktop application that "has to work on both windows, mac and some popular linux flavors.". So I guess he doesn't cares about Solaris.Mose
S
6

I don't think there's any one right answer to this question, but my advice would be to stick with SWT unless you are encountering severe limitations that require such a massive overhaul.

Also, SWT is actually newer and more actively maintained than Swing. (It was originally developed as a replacement for Swing using native components).

Scilicet answered 22/5, 2013 at 14:56 Comment(1)
SWT never was intended to replace Swing. How so? Swing came with Java from SUN and SWT only runs on 4 or 5 platforms and comes originally from IBM and was further developed in the Eclispe Foundation. If at all you could say: SWT aimed to replace AWT.Glucinum
O
1

On older notebooks with integrated video Swing app starts and works much faster than JavaFX app. As for development, I'd recommend switch to Scala - comparable Scala Swing app contains 2..3 times less code than Java. As for Swing vs SWT: Netbeans GUI considerably faster than Eclipse...

Oilskin answered 8/9, 2014 at 20:37 Comment(1)
Scala Swing is good to mentionGlassblowing
I
0

I'd look around to find some (3rd party?) components that do what you want. I've had to create custom Swing components for an agenda view where you can book multiple resources, as well as an Excel-like grid that works well with keyboard navigation and so on. I had a terrible time getting them to work nicely because I needed to delve into many of Swing's many intricacies whenever I came upon a problem. Mouse and focus behaviour and a lot of other things can be very difficult to get right, especially for a casual Swing user. I would hope that JavaFX is a bit more future-orientated and smooth out of the box.

Intolerance answered 22/5, 2013 at 14:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.