Swing and the AWT

In early versions of Java the graphical interface was implemented using a set of libraries called the AWT. AWT was designed to use the “native” widgets or controls on each supported operating system. The problem with this is that it meant that a widget could only be supported if it was present on all platforms. So if one operating system did not support a combo box (a combination of text box and list box) none of them could. In addition this “lowest common denominator” meant that AWT applications looked equally bad on every supported platforms. So whilst users of the Apple Macintosh were used to using very visually appealing programs, perhaps verging on the beautiful. As soon as they ran a Java AWT application they were looking at an interface that was one step up from a text based screen.

To get around some of these limitations Sun developed a replacement for AWT called Swing. The Swing system has more controls, a better appearance and what is known as as a Pluggable Look and Feel (or PLAF). By virtue of this, a program on the Macintosh actually looks like a Macintosh program, and a Windows program looks like a Windows program. With a single change in a line of code you can turn a program from one Look and Feel to another.


   UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
   //UIManager.setLookAndFeel(new com.sun.java.swing.plaf.motif.MotifLookAndFeel());
   //UIManager.setLookAndFeel(new com.sun.java.swing.plaf.metal.MetalLookAndFeel());

The Pluggable Look and Feel of Swing allows a Java application to have the appearance of the native Operating System

Whichever line is uncommented, the program will take on the Look and Feel. Thus the following to images are the same code except one is using the Motif, one the Windows look and one the Metal. (You can only run the Macintosh look and feel on Macintosh hardware due to the litigious nature of the Apple Computer company).

The Metal (Java) Look and feel

The Windows Look and feel

The Motif (Unix) Look and feel

SWT

I will only mention SWT in passing so you know what it is, rather than explain how to use it. Although Swing is generally a big improvement on AWT it has been criticised for performance issues. Engineers at IBM decided that they could do better than this and came up with the Standard Widget Toolkit, which like AWT used the widgets in the underlying platform. Unlike AWT however rather than take a “lowest common denominator” approach and give an interface that looks the same on each platform, SWT adopts the look of the native platform, and offers good performance. You can see SWT in action in the eclipse project (http://www.eclipse.org). In my view SWT is interesting but is not the standard in Java programming and unlikely to become the standard, so unless I have a very compelling reason to look further into it I am happy to leave it to the engineers behind the excellent eclipse development tool.

Last modified: Thursday, 24 July 2014, 2:54 PM