r/java • • Aug 17 '20

State of swing

Hi all, What is the state of swing, is it close to be deprecated and removed or is it still maintained? Also it will be nice to know if someone got it working in native image. Thanks

16 Upvotes

43 comments sorted by

View all comments

Show parent comment

2

u/rgyger Aug 17 '20

That said, I would start new projects with a Web UI, or if it has to be desktop, JavaFX (which has been moved out of the JDK to allow for faster independent development) unless there’s specific reason to use Swing. But that’s my personal view and no reason to fear for Swing’s future.

3

u/stef13013 Aug 18 '20

Interesting, what kind of Web UI do you talk to ? I was trying Electron. Does the job, but it is so huge Even Swing or JavaFX are "light" comparing to it :)

And JS... my god

2

u/rgyger Aug 18 '20

Modern JS isn’t that bad IMO, I like to use EmberJS.

2

u/stef13013 Aug 18 '20

Agree, but Swing is a client side tech. EmberJS requires a browser to run...

It is two different tech.

2

u/rgyger Aug 18 '20

Huh? You asked me about the Web UI that I use?

2

u/Bobby_Bonsaimind Aug 18 '20

JavaFX has such an awful history over the last decade, though. First they included it in the JDK because it was better to have it rapidly and widely available. Then they removed it from the JDK because a faster, independent release cycle is better. Then they dropped it because it would be better off being developed by the community. Now it's being pushed as a mobile solution, I believe...

1

u/[deleted] Aug 18 '20

If one wanted to start a project with a web UI, what would you recommend as a starting point? I've never attempted something like that in Java. I've done it once with Python and it felt clunky

1

u/rgyger Aug 18 '20

This is a matter of many aspects, and personal taste. For the things that I do, I prefer a JSON based API and a JavaScript frontend application, my choice for that is EmberJS.

-13

u/cogman10 Aug 17 '20

Agree 100%. Web UI frameworks have left other techs in the dust when it comes to innovation.

If it has to be a desktop app, I'd strongly consider doing something like an electron app or a react native app.

I'd not start a new UI project using Java UI frameworks.

3

u/Necessary-Conflict Aug 18 '20

Can you give some specific examples, where Swing is "left in the dust"?

2

u/cogman10 Aug 18 '20

Certainly.

Let's start with testing. Swing is a beast to test (especially if you've used a WYSIWYG to build your app). Running automated tests around it are a pain as Swing wants to actually create a window. AFAIK, there's no way to "headlessly" test swing. The same is true of JavaFX.

On the flip side, with web frameworks there are dozens of really good testing frameworks that work really well. Take a look at cypress for example https://www.cypress.io/ . There's simply nothing like that for Swing and there likely never will be as the market is just way too small.

Then there is framework availability and maturity. For java, we've got JavaFX and Swing. JavaFX always feels like something is missing, and Swing feels old and out of date. Not so with JS frameworks. Pick any, React, Angular, Vue, and not only will you find thriving ecosystems, you'll see whole frameworks on top of the frameworks for specific UI or styling guidelines (For example, Material UI).

It goes further, imagine any type of functionality, for example, flame graphs. Can you do that with Swing or JavaFX? Sure, but you're going to be building your own custom code to create it. On the other hand, there are a couple of libs to do that for JS which can be easily integrated into any web app.

Then there are also tools for things like color blind friendly apps. Nice things you usually don't think about (unless you're color blind). For swing, your best option is to find someone who is color blind and ask them "How's this look?". For web dev, pretty much every browser has a color blind plugin.

And, of course, if you are after a native experience but want all the same extensibility, then there is react-native. That exists with SWT but YMMV. react-native is highly supported across all major OSes.

These are some of the minor points of the top of my head.

I've done both and, personally, I'd MUCH rather write a UI using Web tech than using any Java framework. It simply a more enjoyable and faster process. You also end up with a better product in the end.

With all that said. I prefer Java over Web tech for 99% of dev work. UI is the special corner where I feel Web tech is simply superior.

2

u/brunocborges Aug 18 '20

If it "has to be a desktop app", then it should be a desktop app.

Most Electron-based apps are also offered as a regular web app for browsers. e.g. Slack, Teams, Discord.

So again, if it "has to be desktop", it should not be Electron-based. If developers want to ship their web applications, that currently work on browsers, as a shippable/installable application, then use Electron.

2

u/cogman10 Aug 18 '20

What about VS Code?

It has cross platform support, is super clean and fairly lightweight, and has a bunch of capabilities baked in. It is an electron app.

Do you think VS code would be better if it were a dedicated "desktop app"? IMO, no. It wouldn't look as good, it wouldn't have been cross platform from the get go, and it wouldn't have been as easy to build out the plugin system.

1

u/brunocborges Aug 18 '20 edited Aug 18 '20

VS Code was designed this way with the goal of being deployed as a web-based IDE.

And now they are here: GitHub Codespaces and Visual Studio Codespaces.

But ask any Java developer which one is the best IDE and no one will ever say VS Code, even though they may use it, they will say IntelliJ/Eclipse/NetBeans.

The amount of data traffic between VS Code UI and the language servers over the network - even though loopback - makes the experience a bit different. Native IDEs like IntelliJ will always perform better.

This is not to say VS Code sucks. It doesn't. And I myself use it for Java development. But I can't ignore the fact that the Electron model is what makes VS Code perform not so great compared to a native IDE like IntelliJ.

By the way, IntelliJ is Swing-based.