Criticism on SWT

The Standard Widget Toolkit (SWT) is a graphical widget toolkit for the Java platform. It conceived as an alternative to the AWT or Swing toolkits provided by Sun Microsystems. It has the intent for better performance (to run faster and and to consume less memory), native look and feel and deep platform integration.

As there is already a lot of discussion about Swing and SWT on the web and I will not compare them again. I personally prefer SWT because I felt more productive with this toolkit. Nevertheless, I still did not yet feel productive enough to consider SWT valuable. Let me explain why.

Then adoption of SWT requires a steep leaning curve, although there is a lot of good and complete documentation on SWT website. There are also examples, nearly one for each situation you can imagine. As for every new toolkit, learning takes some time.

I liked SWT at the beginning, because it just does what it proposes to do: present the GUI. And it is simpler than Swing and took half the time to learn it. On the other side, if you want to really use SWT, you will need to write all code repetitive that provides data and behavior, or rely on a MVC framework. The only I know is JFace.

I am still impressed how much procedural code is required even for the construction of simple dialogs. You will need to manually instantiate each of the widgets that compose the GUI. And for each of those widgets, you will be required to set most of its attributes manually, since default values seldom meet the expected ones and there is no configuration for default values to achieve an application wide uniform GUI.

Also, laying out the widgets on the GUI is still very confusing and requires even more code. There are several layout managers that are, although simpler than on Swing, still complicated enough. Every layout detail needs to be programmed individually  again and again.

I feel that SWT layout managers are unable to take intelligent decisions when packing (calculating size and position for) the widgets: many widgets will adjust to unusable size (like zero width/height) if you forget to set smart hints for both width and height. There are many situations when you will be forced to write (repetitive) code do adjust the layout for better size and positioning. Even simple forms achieve extreme complexity to have fields aligned to their labels and dialog borders. I needed to develop a coding methodology in order not to get lost among hundreds of lines that define alignment of widgets on a simple form.

I think that SWT, as does Swing, misses a productive way to describe structure (parentship of widgets), layout and formatting in an independent and parseable way, outside of your code. Therefore, there is still no quality IDE to draw your GUI as it was possible on Delphi or Visual Basic. There are some interesting initiatives that propose setting formatting of widgets using CSS and describing parentship with XML. I have not seen a solution for layout, but I think this could be achieved also through CSS. Probably, people will finally recognize that SWT or Swing dialogs should follow a similar approach than web pages: to separate structure (HTML) from presentation (CSS). Why not have a designer layout your GUI and leave the programming work for the developers, as people do for web applications?

Although SWT claims to be platform independent, SWT still often requires hard coded platform specific information. One example are the width and height hints for widgets, that are measured in pixels (therefore, platform dependent). Or you may implement (more repetitive code) calculations based platform properties in order to get reasonable values for hints. Other platform dependent issues that are quite awkward are setting color and font (ex. switch a label red or bold on error).

At last, I was a bit disappointed that SWT is not portable out of the box. On each platform you will be forced to adjust your classpath to include the appropriate .jar compiled for the platform. This means that you will not be able to deploy a single jar that runs everywhere, as it would be supposed.

I admit that SWT addressed may issues that had not been solved before on Java and that SWT proposes a simpler model than Swing to build GUIs (I do not state that this was good or not). Nevertheless, SWT failed to achieve the developers most important goal: to get productive in less time. SWT still requires a large amount of repetitive and boring programming effort.

4 Responses to Criticism on SWT

  1. Tony Lopes says:

    Have you tried MigLayout?
    I think it addresses many of the issues you cited. I tried it with swing before and it worked pretty well.

  2. Pingback: Vintage Book – Show Boat By Edna Ferber : Boat Articles

  3. Pingback: Vintage Book Show Boat Roast Beef Edna Ferber Lot Of 2 : Boat Articles

  4. Bob says:

    Use SWT Designer (it is downloadable from the default download sites in the Eclipse downloads manager).

    No more coding to design GUIs, Just drag and drop and design the GUI graphically.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: