What's the deal with Swing?

Bryan Sant bryan.sant at gmail.com
Wed Mar 29 11:23:33 MST 2006

On 3/29/06, Dave Smith <dave at thesmithfam.org> wrote:
> > Qt is awesome.  The best UI toolkit in the world for sure.  Too bad
> > it's GPL or $2,500 per developer seat.  :-(
> >
> Indeed. A price my company gladly pays to use it. Trolltech's support is
> awesome too (which is rare for commercial software, I've found).

I'm not saying it's not worth it.  I'm just saying it's a significant
barrier for many would-be Qt users.  Technically, I can't even dabble
with Qt unless I first choose to make my project GPL or pay up in
advance.  If I don't have an employer who will play for Qt up front
then I'm out of luck.

> So you have to use third party layout managers to improve your Swing
> experience.

No.  GroupLayout is built in to Mustang (Java 1.6).  BoxLayout exists today.

> > No.  As long as someone has a 1.5 or better JVM, the JNLP descriptor
> > will tell them that they need a newer JRE to run your WebStart app (if
> > you require a newer JRE) and the older JVM they have will know to
> > download the newer JVM to run your app (with the user's permission).
> >
> But they still have to be savvy enough to download and install the JVM.
> Anything more than Next Next Next will confuse Windows users. :)

Yes, they have to have a 1.5 JRE in the fist place, but then after
that they don't need to be savvy.  They click your WebStart link and
if a newer JRE is required, they click "Next", "Next", "Next" and
they're up and running.

Also, most (I've heard 75%) of all PC's shipped today are shipped with
a modern Sun JRE pre installed.  Read about how Dell and HP ship the
latest JRE with all of their systems here: 

It's not as good as being Microsoft and dictating what goes on a PC,
but most of your customers will have the latest JRE.  I'd still bundle
the JRE with my app though -- just to be safe.

> That's an order of magnitude larger than any Qt GUI installer I've
> distributed.

Well are we comparing it to Qt or "today's standards".  Compared to Qt
it is laughable how big the download is :-).

> I think Ocean looks pretty good, but it still doesn't look native by
> default. To most users, that means "weird" at best and "ugly" at worst.

Agreed.  I think that 1.6 defaults to the "System" (native) look and
feel.  If not, you just add the following environment var on Windows:


Or this on Linux:


Now all apps default to the native look and feel.

> Yup, Qt is line-drawn, but for whatever reason it's always been quite
> fast, even on 3-year old computers. Plus, it looks "right." Why doesn't
> Swing look "right" by default, and why hasn't it always been fast?
> (sorry, those are rhetorical questions).

Swing hasn't always been fast because they're just now using hardware
accelleration (and the JVM has gotten much faster).  Qt would be slow
too if it didn't use hardware acceleration (but it always has).  Now
Swing uses hardware acceleration (DirectX on Windows and xv (I think?)
on Linux).  The next release will use Direct3D and OpenGL
respectively.  With the texture caching aspects of the 3D
technologies, Swing will be even faster -- it will likely be even
faster than native components that aren't using 3D API's to paint.

> Unless I'm mistaken, you still have to draw all of JCanvas's items with
> paint methods. You can't instantiate objects that live on the JCanvas,
> draw themselves, animate themselves, know their velocity, etc. You have
> to keep track of all that. And yes, JCanvas has always been
> double-buffered, but not by default. You had to turn it on (not sure if
> that's changed). QCanvas is double-buffered by default.

Well technically there is no JCanvas.  In Swing the component you want
to use is JPanel and you can add any other Swing component to a JPanel
and they all paint themselves.  You can override any Swing component's
paint method to do custom painting on that surface too.  JPanel is
just the lowest "canvas"-like component.  You are right that
double-buffering is disabled by default -- be sure you call

> Yes. What I mean here is that it is easier to make quick and responsive
> GUIs in Qt because it is fast by default. You don't have to use Worker
> objects or some 3rd party library just to make your GUI reasonably
> responsive. You just use the normal Qt classes, and your GUI will be
> responsive, always. That's what I meant with "by default".

This is my biggest complaint with Swing.  You have to understand
threading and how to spin things off the event thread for Swing to be
responsive.  Threading isn't hard (IMHO), but many people don't
understand it well, and so they don't spin things off, and thus there
are many, many, many CrAPpY Swing apps.  Qt did it right.  It was a
mistake that Sun made in Swing's design (though they'll defend it to
the death).  SwingWork isn't 3rd party -- it's built in to 1.6.  Spin
is obviously 3rd party, but most Java developers are totally
comfortable with using 3rd party libs -- componentization actually
works in the Java community.

> I'll grant you that. Is the version of Netbeans you refer to available now?

Yes.  Netbeans 5.  You can get it here:  www.netbeans.org

> A lot of the stuff you said will depend on Java 1.6. Would that imply
> that Swing is about 2-3 years behind Qt?

At least.  But the the velocity of improvement in Swing is high.  I
think it will catch up...  Or it will die.  They can't afford to suck
anymore with SWT and WinForms (and Qt or GTK+ or wxWidgets) as viable
x-plat competition.

> Anyway, I think this has been a pretty productive conversation on Swing
> vs. others, and I'm glad to see that it hasn't degenerated into an ad
> hominem flame war.

What!  This can't be PLUG then!  :-)


More information about the PLUG mailing list