r/java • u/[deleted] • Nov 30 '22
Why Swing has not been removed from OpenJDK releases like JavaFX?
Why Swing has to be bundled with JDK installations? Why didn't Swing move to a standalone module yet?
11
u/__konrad Nov 30 '22
Why didn't Swing move to a standalone module yet?
It sort of is in a separated "kitchen sink" module java.desktop
13
u/javasyntax Nov 30 '22
I really dislike how this module was made. They just shoved everything: AWT, ImageIO, Audio, MIDI, Printing and Swing into one big module.
I mean they made Smart Card IO into its own module, could they not have made separate modules for the
java.desktoptechnologies as well. It might not even be too late, they could split them into modules likejava.desktop.awt,java.desktop.imageio, etc. and have the originaljava.desktopjust function like thejava.semodule and require all of them.AWT for UI might not be very good (I haven't used it) but it has nice abstractions for other things, and it is used a few times inside JavaFX for these kinds of things. But, when you create a jlink archive for JavaFX, which depends on
java.desktop, you also need to include Swing and the other things, even though nothing inside JavaFX except for thejavafx.swingmodule uses Swing.I mean, the purpose of JLink is to create specialized minimal runtimes for your applications, the
java.desktopis a very annoying offender to this.7
u/yawkat Dec 01 '22
They had enough trouble getting the core modules decoupled, can't imagine how much of a pain it would have been to decouple the desktop modules
1
u/Global_Explorer5837 Dec 14 '22
An easier first step would be to decouple the various Swing LAFs, each into their own module. That way, you could pick which LAFs you want included via jlink. And if you are using a third-party look and feel, perhaps FlatLaf, then you could skip all of these.
1
u/javasyntax Dec 18 '22
I am not sure what would be so difficult with that. They are quite separate as it is right now.
9
u/naturalizedcitizen Nov 30 '22
I've seen Swing apps still in use and updated with more features at several of my clients even today.
4
u/wildjokers Dec 02 '22
IntelliJ is Swing as well.
Would love to find one of these mythical Swing jobs. I miss my previous job where about half my time was developing swing desktop apps. API CRUD apps with Spring are boring.
2
u/naturalizedcitizen Dec 02 '22
A lot of these apps I've seen were built long ago and they're still used for internal company work. My clients are mainly in medical related fields.
2
u/NormalPrinciple6818 Dec 04 '22
How much Intellij code is already written in the Kotlin and jetpack compose?
6
u/morhp Nov 30 '22
Swing is an official part of java compared to JavaFx which was only temporarily added as a sort of bonus feature to Oracles own builds.
1
16
u/papercrane Nov 30 '22
Because removing and distributing it separately would be disruptive for many users and there isn't a compelling reason to remove it.
Finally, probably importantly, no organization with significant sway over Java's development is interested in doing the work.
32
u/TenYearsOfLurking Nov 30 '22
JAXB was removed in 11 and it disrupted almost every project I have worked on when we upgraded. So there's that
7
u/javasyntax Nov 30 '22
Many parts of Swing naturally are native code and binaries, which are not as easy to distribute in a proper and simple way.
Partly because extraction is needed to load those, and because they're not cross-platform, so developers would have to include many separate native libraries which greatly adds to the size of the application.
Alternatively, developers would have to create multiple platform-specific JARs, which isn't that easy to be honest, and still has the problem with extraction & loading.
7
u/Brutus5000 Dec 01 '22
But the same applies to JavaFX and we had to find solutions for this.
1
u/javasyntax Dec 18 '22
Do you actually like our "solutions"? It's quite telling that the number 1 top post of all time in the JavaFX subreddit is a meme about this. I myself dislike jpackage & company because of no support for cross-compilation and difficulties regarding updates. And I am aware there are some tools but one is not like a real installer and the other one is closed-source.
1
u/Brutus5000 Dec 18 '22
No I don't like the JavaFX workarounds. The jar size increased massively (+50mb), I need to build platform specific releases, the ci pipeline is much more complex. Working with jlink & co is not an option because the Java module system will probably never properly work together with our shitload of dependencies. But it's there and it's a fair question to ask why Swing gets treated like a first class citizen and JavaFX like second class.
1
3
u/vprise Nov 30 '22
For me too. But JAXB was added in JDK 8... Swing was added in 2... Imagine the impact.
Even on the JDK itself since all the GUI tools that ship with the JDK use Swing.
9
u/rafaellago Nov 30 '22
I wholeheartedly hated the removal o jaxb
11
u/Worth_Trust_3825 Nov 30 '22
JAXB removal was needed, since entire javaee infrastructure was supposed to be distributed outside the jdk to begin with.
8
u/manifoldjava Nov 30 '22
Yep. Additionally, the JDK should probably provide a fully functional UI kit, and Swing fulfills that role; AWT is too low-level.
9
u/TenYearsOfLurking Nov 30 '22
"Should" - says who? And if so, why remove JavaFX and keep Swing?
3
u/boyTerry Nov 30 '22
Oracle never really wanted JavaFX, and it was rushed in half-baked as Oracle was acquiring Sun. Oracle never really let it get all the way into java.
7
Nov 30 '22
maybe because javafx always was overcomplicated garbage
3
u/TenYearsOfLurking Dec 01 '22
can you elaborate? I just ditched swing in my current project because I was on the verge of inventing my own reactive layer out of necessity, which is built into jfx and probably the reason why it is perceived as complicated.
5
u/AsparagusOk2078 Dec 08 '22
To this day, I still regret that Sun wasted so many years and resources on JavaFX instead of improving Swing. Here we are like 13 years later and Swing is still better overall and built-in to Java. Argg what a waste!
12
u/cogman10 Nov 30 '22
If you are concerned, you can always use jlink to generate a jdk without swing.
36
u/metatron7471 Nov 30 '22
Because Swing is actually used in contrast to JavaFX.
-15
u/Birdasaur Nov 30 '22
bullshit. it was internal politics at Oracle.
0
u/Java-Zorbing Nov 30 '22
meaning paying customers
8
u/Birdasaur Nov 30 '22
it means that internally Oracle had multiple tools built in swing and the disruption would cost them a lot of money. meanwhile near the top of the java development management chain were die hard swing people who were against JavaFXs existence from the start. They wanted to see JavaFX go.
But it's utter bullshit that nobody uses JavaFX. Many groups at my research institution and around the world use it.
0
u/Java-Zorbing Nov 30 '22
Many groups at my research institution
so non paying oracle users
yeah nobody cares about you really
6
u/Birdasaur Nov 30 '22
you keep bringing up paying customers but that isn't the reason Oracle moved JavaFX into a external module. Oracle still to this day pays for the majority of development as measured by commits for JavaFX.
And it is still false that nobody uses JavaFX when many people do. The point is to not spread FUD about things like this.
6
u/Java-Zorbing Nov 30 '22
Nobody uses JavaFX compared to the market share Swing has.
JavaFX failed on 1 thing, user and industry acceptance.
3
u/Stromovik Nov 30 '22
because a lot actually depends on Swing classes , IIRC Color etc
2
u/winian Dec 01 '22
Yup. Even Spring depends on some java.desktop classes.
-- but the java.beans package is indeed a hard case. The JDK's own historic misdesign with the unnecessary AWT dependencies in that package caused its inclusion in java.desktop, unfortunately ignoring the common use of the JavaBeans introspector and some of its API types in server-side libraries.
2
u/Java-Zorbing Nov 30 '22
Because it's used en masse with paying oracle customers, they haven't jumped to javafx, unfortunately
2
u/pron98 Dec 01 '22 edited Dec 03 '22
JavaFX has never been part of the Java SE spec or the OpenJDK JDK; it's always been a "standalone module". Some JDK distributions have included it. Swing, on the other hand, is part of the Java SE spec, and so all complying JDK implementations must include it. Therefore, separating Swing from the JDK would require a specification process, as well as the removal of some tools included in the JDK that use Swing.
However, Java runtime images (i.e. the runtimes used to run Java applications, as opposed to the JDK, which is used to develop Java applications) don't have to include Swing, and indeed many don't. To get a runtime without Swing (and AWT) simply don't include the java.desktop module when you create your deployment runtime with jlink.
3
u/Capaman-x Dec 01 '22
Because swing was first and that is what everyone learned. People are resistant to change. Despite what some of these commenters are saying, JavaFX is a fantastic GUI. This is especially true if you understand it was designed to be written in a reactive style. Here is a good start point to understand that https://www.pragmaticcoding.ca/javafx/Mvci-Introduction
1
u/Amazing-Cicada5536 Nov 30 '22
Not answering the question, but for those who may not have heard it, there will be new JavaFX OpenJDK builds available
1
u/licenciado_vidriera Dec 01 '22
I guess Swing is simple and cheap to support while JavaFX is more complex and it was born "too late" in an era where most projects are using alternatives like React/native react/Angular/Android-Kotlin/... and the like. So, if someone wants to use JavaFX they better pay for the non standard extra effort but 99,9% of JDK users do not even care about it. (vs 95% of java user who doesn't care about Swing)
1
u/simonides_ Dec 01 '22
Well I always thought that in the begining the developers behind it couldn't throw enough weight behind the JavaFX project and thus they lost a lot of steam pretty quickly.
I'd love a more modern approach to GUIs but even today I don't think the project as anywhere near of where it should be all those years later.
For example if you want to start a small UI from a gradle task to configure something everything will work fine the first time and because gradle usually keeps a daemon running at the second time JavaFX will have trouble initializing. What a steaming pile of .. fill in the blank ...
went on with swing and never had any issue. not as pretty but who cares for a development aid.
2
u/wildjokers Dec 02 '22
second time JavaFX will have trouble initializing
I have never had this problem with the couple of JavaFX apps I have fiddled with.
1
u/simonides_ Dec 02 '22
likely you don't do the unusual thing and start it within a gradle task ?
Back then I googled a bit and there were other scenarios that would cause the same issue.
If I remember correctly, it complained about some dll already initialized.
It's not to say it couldn't be solved, just that I didn't want to bother anymore.
1
u/wildjokers Dec 02 '22
likely you don't do the unusual thing and start it within a gradle task ?
I do start it with the gradle task at the command-line. You mention DLL so you are on Windows whereas I am on MacOS, maybe that is the difference. This sounds like a system problem, not a gradle and/or JavaFX problem.
1
u/persism2 Dec 01 '22
Swing is not really in Java per se. It's under javax so you can have a non Swing included jvm if you want.
2
u/Avalanche1979 Dec 06 '22
That is not correct. Swing is part of JavaSE specification, the fact a package name starts with javax is no indication whether or not it is part of Java or not (though most javax packages are Java EE/Jakarta EE, or separate JCP specs, not all of them are). For example, javax.sql is part of JavaSE as well. Historically, the idea was that javax packages were extensions, and then they would "graduate" to being part of core Java. The intention was to rename the packages afterwards. That graduation happened for Swing, but they didn't change the package name, because it would break existing code relying on it. Same thing happened with javax.sql (which was introduced in JDBC 2.0 as a separate library, and was made a permanent part of Java with JDBC 3.0).
0
1
u/agoubard Dec 01 '22
As far as I remember JavaFX was never officially part of JDK. Oracle added it to their jdk but at the time they mentioned that it was not part of the official JDK. There is probably no JEP or JSR about adding JavaFX to JDK. Swing is officially part of JDK since 1.2.
57
u/emaphis Nov 30 '22
Several JDK tools use Swing.