Skip to main content

Swing in a better world

Posted by alexfromsun on March 9, 2011 at 11:58 PM PST

I truly love the Swing GUI toolkit, I enjoy its flexibility, opennes and great abilities.

I know that some people say that Swing is too difficult to learn,
and I partly accept it because it took me several years working in the Swing team
to get the whole picture of the AWT, Java 2D and the Swing itself.

The Swing history counts more then 10 years and it is definitely not about end.
The new features have already been added to JDK 7
and the new blogs are coming to describe them.

Swing is the best graphical toolkit I have ever worked with,
anyway it could have been implemented even better.

Even the best piece of software in the world would have bugs
and design glitches. At this point I want to stop for a moment,
to look back and remember the cases when
I wanted Swing to be designed in a different way.

This information may be useful for all developers
who are working on any other graphical toolkit.

Swing is written in Java,
so its API is tightly bound with Java language peculiarities
and event high level decisions of the Swing architecture are affected by the language sometimes.

So I'll cover the java related issues first
and then touch some exclusively Swing features.

Java related issues

Swing design


Related Topics >>


<p><!--[if gte mso ...

Hello All

It is very nice to see that Mr. Alex is still with us.

I would like to use this forum to express some frustration, excuse my offense.

I believe that whether Swing could be better or not is simply not the point. Just look at netbeans and all the other developer tools. What other tool can make the tools to do graphic interfaces? JavaFX is 100 light-years away of being able to do something like that. But that's not the point.

I keep on hearing people like Amy talking about "User interfaces in collision with graphics" in 2011?? Stop it!, we have been arguing about this since the past century. There is a place for fancy artistic interfaces, like commercial web pages and juvenile cell phones. That is great, but it is a very different thing from day to day business applications and developer tools.

I don't know about you guys, but I'm getting really tired trying to explain why markup language and ornamental oriented UIs are one thing and business or developer tools another, and why we need different and _separate_ tools. The one has to be easy and pretty, the other flexible and functional and, hence, more complex.

JavaFX is great, but for me, and lot of people I believe, seeing fancy bubbles in a screen demo is nonsense. There's not even a grid component or a printing framework! It feels like the first try of the AWT 10 years ago.

I'm confident swing is here to stay and evolve. If it is replaced, it will not be by JavaFX, definitely.

Anyway, thanks for your patience with this vulgar rant. By the way, these are some of things I've been doing for the past years with Swing, which I'm sure you will have fun looking at: … plus some help would be really appreciated.

Great to see you're back with

Great to see you're back with your amazing blog entries, Alex! Thanks for the help and clarification on many diffucult questions for my second edition Swing book, I mentioned your name there, it's out and available since January, I can send you one if you'd like.. Keep us informed on all latest and greatest in Swing, and not only Swing, world!

Wow, Ivan! It is nice to see

Wow, Ivan!

It is nice to see you here my friend,
I would certainly love to read the book.

Swing team doesn't mind to have the signed one from you


Swing in a better world

Hello! Another long time java developer here.
Swing is a powerful toolkit and the customization potential is simply awesome. I'm still learning new stuff (mostly related to java2D) and new ways to extend existing components.
Most of the problems with swing (IMO) are/were related to poor tutorials and just plain wrong instructions from the early days. Some of those idioms live even today, and it can sometimes be frustrating to find the gems amidst the rubble.

Swing in a better world

I use Swing since 2000 and don't think that it is difficult to learn. Every new framework has its own APIs and "extras". If a Framework wrapps the technology behind you have to learn the framework and not the technology behind. If you work with the technology you have to learn it and maybe create a framework around that solves your problems - or better check if there are existing frameworks.
You don't have to be a top-class developer to understand Swing, but you need time to learn. And there are enough tutorials, examples, howtos available! You have the same problems with other APIs/frameworks like Netbeans RCP, SWT, QT, WPF, ...
In my opinion, the problem is that developers get tasks and need solutions for that tasks. Many developers don't know how to develop a framework and so they start developing a solution... Maybe the solution is not reusable... And it depends on the complexity how easy it is, to develop the solution. (Not really new information), and of course how many frameworks you need and need to know.
Back to JSR-296: It was a good idea but I think it solved only the first problem: How to start developing an application and how to start using actions.....
After the first hurdle, a developer has the next problem: How to solve my task. The application frame works and screens are configured, but how to sovle common problems like: Session Management, User authentication, Database access, ....
I know that a lot of frameworks exists in the Java world with which you can solve every problem. But the effort to dive into multiple frameworks is high and you need specialists.... I think that JSR-296 is a good base but for me, an Application Framework solves common tasks and reduces boilerplate code. And there are not many frameworks available which solves application development problems!

Swing in a better world

I liked development with Swing. It's archytecture is really great.
But never liked it's default look and feel. Can't understand why it does not look like Adobe Flash.

Swing in a better world

The Metal Look and Feel sucks indeed, the new Nimbus LaF is much better

I love Nimbus Laf but it has a lot of bugs in it. Some of ...

I love Nimbus Laf but it has a lot of bugs in it. Some of the UI defaults are not working :(

Swing in a better world

Despite Swing being a great library, what is its future? Swing App Framework (JSR 296) was abandonned and JavaFX seems to be the next Desktop Java library.

Swing in a better world

gquintana wrote:

Despite Swing being a great library, what is its future?

Alex, I think your reply only answered the second part of gquintana's question. I think the first part (which I've quoted here) is something a lot of people wonder. I'll be interested to read about new Swing features in Java 7, but I'll be far more interested to know what's planned for Swing in the next five years since it was largely ignored during the last five years.

Swing in a better world

The Swing and JavaFX relations are described by Amy.

About the future of Swing I can say two things
first - that Swing is a part of Java API so it can't be taken out from JDK
second - JDK 7 is coming and we have some new features there

Swing in a better world

> JDK 7 is coming and we have some new features there
Oh please and this is why you've written this oddly formatted article that talks about Swing in the past tense? it reads more like a eulogy. Amy's comments make it clear Oracle see Swing as a legacy API only and unfit for modern UIs.
What new Swing features are in JDK7? Nimbus, J(X)Layer and the other Java6u10 rendering additions that had been missing from Java 7 till recently. As the roadmap for JDK8 is being mapped out why dont you tell us whats in store for Swing in JDK8? Cant you promise its not a Java2D/Swing/AWT jigsaw module of their very own so these 'legacy' APIs can be made optional?
Even with JDK7 you've broken your precious prime directive that all code in the previous version runs in the next without changes because they've relocated the Nimbus packages. There's several ways APIs can cope with change. The no changes law didnt always apply to Swing, Swing 1.0 code won't compile under Java 6, in the same kind of ways JavaFX 1.0, 1.5, 2.0 etc.. aren't binary compatible. That's not even taking into consideration all the Swing regressions over the years where developers have to check the Java version to compensate for changes to the default behaviour of the previous version. No changes seems as much an excuse for the comparatively scant resources thrown at client-side Java over the years as much as anything else. Now you expect developers to trust in the JavaFX APIs and they they won't be just as shoddly treated, again.. despite it running far short of its orginal promise of running on all the screens of your life. The truth is client side Java has never been so threadbare as it is right now.

Swing in a better world

Swing App Framework is currently on hold, but it I don't see it as a big problem.
The goal of JSR 296 is to help Swing newcomers when every existing application
uses its own framework which is different from anything else.

We should have introduced a framework in the early days of Swing,
currently this is not a priority.


Swing in a better world

alexfromsun wrote:

Swing App Framework is currently on hold, but it I don't see it as a big problem.
The goal of JSR 296 is to help Swing newcomers when every existing application
uses its own framework which is different from anything else.

We should have introduced a framework in the early days of Swing,
currently this is not a priority.

This however is unfortunate, because I believe that a good framework could overcome many of the difficulties developers have with learning to use Swing. I know that many people assert that GUI builders are the solution to this problem, but historically they have never worked well.