Skip to main content

Should Swing be killed to force JavaFX usage?

Posted by sean.mi.phillips on December 2, 2013 at 11:16 AM PST

Recently I have come upon a blog article which discussed why Swing has to be Deprecated.  My understanding of the author's argument was that since Swing looks ugly compared to HTML5 and nobody uses Swing anymore that it should be deprecated in favor of JavaFX.  The theory was that by deprecating Swing and forcing users to upgrade to JavaFX then all Java GUIs will be better with the ideal world of the mobile and desktop app worlds being one in the same.  The author is apparently a professor for programming (assumption at university) and teaches to his students that nobody actually uses Swing in the real world.  (wow)

This discussion is interesting to me because I find myself deploying a strong combination of Swing and JavaFX using the NetBeans Platform. These views are almost all in support of NASA ground system software, typically behind a DMZ’d sub-network but I also build the tools to be deployed to an analyst’s desk. So my interfaces must look good AND be very usable or nobody will use my software. 

Well I have some problems with how this argument is being presented though I understand why the author is arguing.  If you follow the discussion of the article you'll find many people seemed to take exception to the article.  (a few did agree) The above article seemed to be more of a venting session then a carefully planned argument.  However it is a valid point of view and merits debate so allow me to present my antithesis to further the discussion:

1. Swing is Ugly and HTML5 usually looks nice so we need JavaFX to be nice too!

I've seen some FUgly HTML5 sites and some beautiful Swing apps.  Now what?  Oh we're talking about the typical and not the norm?  You mean like all the "Flat UI" HTML5 web pages that have consumed hipster desires lately yet look like a screenshot from Windows 1.0 or the Amiga Workbench?  

image

Hey there's no borders!  This must be that hawt gnew HTML5 stuff the kids are raving about!

The real problem is that a lot of young developers are trying to ram HTML5 web apps into spaces that Native Applications make the most sense. And why? NOT because of Swing… but because the Java alternative to HTML5 (Swing or JavaFX) isn’t compelling to them. They don't care that they must run their scripts out of a browser (This is SOOO much better than compiled on the JVM right?)  They don't care that their performance drops orders of magnitude and that usability drops quickly compared to a custom Native App.  There are only two things they care about:

1. Does my app look shiny? (Way more important than functionality)

2. Is it really easy to make? (And I mean copy paste in text editor and refresh)

Well HTML5 gives them both for simple data entry, bottom rung UI's and NEWSFLASH.... that's all the pointy haired non-tech managers care about either.  Killing Swing and forcing everyone to move to JavaFX does not mitigate either point because a) the current JavaFX shininess is the same as the HTML5 shininess (CSS) and you have to compile JavaFX while you don't compile your HTML5 code.

2. JavaFX is better because it supports CSS

The more I use JavaFX (2.x) to implement certain views of the various data sets the more I like it.  It's nice and smooth and making good looking interfaces is so much easier.  However that’s all it really provides that Java/Swing did not before … an enhanced skin. I could already do everything I can do in JavaFX 2.x in Swing except the CSS styling.  I could always do nice charts, web browsing and media playback using third party free libraries.  With the exception of Java 8′s integration of JavaFX 3D, the only incentive I have to use JavaFX is the code footprint tends to come out simpler for the flashier things.

How many ways are there to pop a message or show a dialog? How many times are you going to want a different looking menu?  Are you more worried about style or getting the damn app out the door so you can get on to solving your problems? So why deprecate Swing when it is such an effective workhorse? Why does Russia still launch the simple but limited Soyuz design after 50 years? Because it works and they have no real incentive to improve. I think that is the crux of the matter.

3. Deprecating Swing will merge the Desktop and Mobile space

False.

What if Swing deprecated tomorrow?  There would be a lot of butt hurt and everyone would be busily porting their applications to the Mobile compliant JavaFX platforms.  Oh wait JavaFX isn't mobile compliant other than vm's and the brave community ports which generally aren't feature complete or stable.  In fact barring some showstopping surprise announcement from Oracle in the next few months before Java 8 GA, JavaFX won't realistically support even Android until Java 9.  See you in a few years.  So why would anyone bother with upgrading from their hypothetically deprecated Swing code to JavaFX?  Well speaking from over a decade of Mission Critical operationally deployed Swing apps... nobody would.  Too much risk and not enough reward.

What to do?

Here is my offered synthesis of ideas.  First off don’t deprecate Swing… give us some better reasons to use JavaFX. Better 3D! Better and Faster Chart Control! Expanded Media support!  Give younger developers a reason to use Java (FX) at all instead of HTML5 which is eating Java’s lunch. Deprecating Swing won’t stop that because JavaFX as is just isn’t that compelling, and I’m a strong advocate of JavaFX.

In any tactical business decision you need to chose your value proposition.  HTML5 chose Easy and Shiny and naturally forsakes performance and significant customization.  Swing chose Easy and Performance but forsakes Shiny.  JavaFX so far has choosen... Shiny and Easy and Performance??... but it isn't shinier than HTML5 and it isn't easier than HTML5.  It really faster than Swing (excluding JFX8 3D) and only marginally easier.  To make the JavaFX decision more compelling the framework must focus on performance and ease of development. 

For a real-world use case that may sound familiar to some... when sitting down over two years ago to design the software architecture for the NASA GEONS ground system software I reviewed the various Java application development vectors.  I had developed Defense, Commercial, Embedded and Manufacturing applications in Java using Swing, SWT, Eclipse RCP, Web Start and Applet technologies so I had a great cross-section of experience.  I chose the NetBeans Platform, a Swing based plugin framework.  I considered JavaFX but it was too immature at the time. The Swing based NetBeans Platform offered me rapid development of Enterprise features without sacrificing usability or performance.  The extra eye candy that JavaFX offers was a much lower priority.  As a result my development team saved over a third of the estimated development costs which was passed directly to our NASA mission.

Before this becomes a NetBeans Platform commercial I have a point:  If you kill Swing now by deprecating it you lose out on great mature technologies such as the NetBeans Platform with no truly mature replacement on the near horizon.  (Though there are brave developers trying...)  

Developers are creative but lazy, younger developers more so.  If better more feature rich controls are provided, new development will naturally move from Swing to JavaFX and hopefully from Web/HTML5 back to Java. 

Comments

Extended Reddit discussion here

Extended Reddit discussion here

Clearly whoever created the post you read hasn't tried to ...

Clearly whoever created the post you read hasn't tried to get JavaFX working properly with Spring and Hibernate. Because if they did they would realize that it's not that great :)

That's a good point. Honestly the original post author ...

That's a good point. Honestly the original post author seemed to be coming from a very dated viewpoint given that his JavaFX references were from FX 1.0 days!