LWN.net Logo

Swing and AWT, argh

Swing and AWT, argh

Posted May 22, 2006 14:50 UTC (Mon) by lauwenmark (guest, #37754)
In reply to: Swing and AWT, argh by man_ls
Parent article: Harmony project to get a Swing/AWT implementation

Sun engineers came up with an utterly stupid solution which solved a problem that nobody had. The all-Java (or pure Java in Sun parlance) graphical toolkit was built on top of AWT: with it the interface could sport a Windows look-and-feel on Solaris and viceversa. Very useful.

The problem it solved was that the way AWT behaved and looked like changed a lot between its various implementations. The goal of using Swing was to provide an abstraction layer that made possible for an application to display and behave exactly the same on all platforms - a goal the limited design of AWT was unable to fullfill.
Let's also not forget that Swing provides a MVC model which AWT lacked - that too was a rather important progress.

In the process they created a slow, highly bloated environment and a memory hog, which needed endless optimizations to be barely useful. By the way, all look-and-feels were ugly. This monstrosity was called Swing.

Given that the current implementations of Swing are able to use underlying accelerated graphical capabilities (D3D/OpenGL) where available, the lack of speed Swing had in the past seems hardly relevant nowadays. Now, maybe you have some benchmarks to back up your facts ?
As for the Look-and-Feels, it is mostly a subjective point - and nothing prevents you to develop and use your own LnF if you don't like the provided ones.

So now we are stuck with it forever. In fact, gcj and GNU Classpath are mostly complete except for AWT and Swing.

AWT and Swing are large libraries with lots of classes to implement. And they weren't the most needed classes to implement first. Moreover, no compatibility test suite existed for Swing/AWT, so it is not easy to guess the correct behavior in all cases.

Meanwhile, IBM (and later the Eclipse project) found the time to build a much lighter and faster environment, called Standard Widget Toolkit or SWT. It uses the novel (yeah, right) idea of using platform-specific code internally to display controls, and still presenting a uniform API. It's good stuff. The bad news is: even if you only want to use SWT applications, you still have to carry the burden of Swing.

Other bad news related to SWT: only the Windows implementation is decent performance-wise; the documentation is far from the level of what's available on Swing; SWT programming requires manual ressource-management; portability is inferior, some features not being available on all supported platforms.

Underlining the deficiencies of Swing is one thing - but next time, try not to forget to also underline those of SWT to compare both.


(Log in to post comments)

Swing and AWT, argh

Posted May 22, 2006 17:13 UTC (Mon) by philips (guest, #937) [Link]

> Underlining the deficiencies of Swing is one thing - but next time,
> try not to forget to also underline those of SWT to compare both.

Well, I'm not sure what kind of platform you run, Swing examples run dog slow and unresponsive on my Linux box (AMD64 X2). Anything more complicated than simple text editor is unusable due to very high latencies. (*). GVIM with syntax highlighting open on busy remote server over X protocol tunneled over ssh runs snappier than localy run Swing demos from Java SDK.

On side note, SWT thou not perfect, quite usable - here I'm judging by Eclipse - on both Windows and Linux. I personally use vim - but most of my friends use solely Eclipse with plug for C/C++ as their primary development environment. (**)

Probably Swing is designed better than SWT. It doesn't matter to me much since I haven't seen single worthy Java GUI application using Swing. And I have on network bunch using SWT.

(*) Okay, I'm touchtypist and quite sensitive to such stuff. Probably others are okay with the delays and flickering.

(**) Just recalled. Azureus - BitTorrent Java client - uses SWT and runs on Windows, Linux & Macs. I used it on many occasions on all of the aforementioned platforms. In other words, SWT much more portable than parent tries to imply.

Swing and AWT, argh

Posted May 22, 2006 22:20 UTC (Mon) by man_ls (subscriber, #15091) [Link]

The goal of using Swing was to provide an abstraction layer that made possible for an application to display and behave exactly the same on all platforms - a goal the limited design of AWT was unable to fullfill.
Yes, that is exactly what I was talking about: a problem that nobody had. People wanted their programs to look different on different operating systems, not uniformly ugly. That is why all the other toolkits (Qt, GTK, wxWidgets, the old OPENSTEP) look different on different targets. And still some people don't get it.
Given that the current implementations of Swing are able to use underlying accelerated graphical capabilities (D3D/OpenGL) where available, the lack of speed Swing had in the past seems hardly relevant nowadays.
Hardware acceleration does not magically solve all problems. In fact 3d hardware acceleration solves very specific problems; it does nothing for bloat.
Now, maybe you have some benchmarks to back up your facts ?
Not really, since the question is not that hot any more. Right now I can offer you some home benchmarks which you will not accept anyway (and with good reason).
  • Hello world: Swing 21 MB and .5 sec, SWT 10.0 MB and .1 sec.
  • Window with 100 buttons: Swing 24 MB and .55 sec, SWT 10.3 MB and .1 sec.
  • Table with 1000 rows: Swing 26 MB and .6 sec, SWT 13.3 MB and .3 sec.
  • Window with 1000 buttons: Swing 24 MB and .7 sec, SWT 13.6 MB and .35 sec.
This on Windows 2k with Sun's JDK 1.5. None of them is particularly stellar, but Swing is a hog.
[...] nothing prevents you to develop and use your own LnF if you don't like the provided ones.
Let us see... Yes, boredom prevents me. SWT looks good (or as bad as the rest on my OS) without any efforts.
Other bad news related to SWT: only the Windows implementation is decent performance-wise;
Some years ago I tried eclipse on my old iMac DV, and it barely run at all (whereas other Swing programs just refused to even try). On my old Linux machine running Sun's JRE it worked, not very fast but usable.

Well, guess what: I just downloaded eclipse for my Ubuntu system, and it runs quite fine. Even though (or maybe because) it uses gcj. It is not as snappy as on Windows, but to tell you the truth Gnome is not either as snappy as KDE.

the documentation is far from the level of what's available on Swing;
In my limited experience I don't have complains.
SWT programming requires manual ressource-management; portability is inferior, some features not being available on all supported platforms.
The rest of your concerns should be answered by people more knowledegeable than myself, like Chris Grindstaff. There are one other aspect of SWT which is probably of interest in this forum: SWT is free software. Swing is not, at least until this Harmony thing came along.

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds