Feb
12
2005

I’ve written my last Swing app… (SWT is *so* the business…)

I’ve spent the last month getting to know SWT, and I’ve gotta say that I’ve written my last Swing app. After spending far too long messing with Swing MVC pattern and writing modeller code for my damn combo boxes, that’s it. I’ve had it. I’ve come to the conclusion that I’m just not smart enough to grok Swing.

But I was still missing a decent sized SWT app that would prove me to that humans could write SWT apps and that I could model off for my own mid-sized project. Then I had a good look at the source to RSSOwl – one very funky SWT RSS Reader – and I’m really starting to get a feel for SWT. Full kudos to those guys for putting together a very spunky app with a very nice source structure. One that I can pick up after a little digging and that looks very maintainable.

Booned to know that this thing looks good in the large, and to get a feel for SWT in the small, I ported a small Swing utility app that does some crypto stuff. It’s got a combo, couple of buttons, and couple of text fields to hold the input and output text. Total port time: 1.5 hours. In the process I managed to dump the two third party libs I was using to make the thing look good (JGoodies forms and JGoodies looks).

I initially did the layout with the SWT FormsLayout, and later made the switch to a straight SWT GridLayout since the overhead of layout data for FormsLayout was starting to urg me (and the layout was a simple grid anyways, really). The app was snappier to start up (half the time of the swing app on JDK 1.4.2 on Win32), and best of all looks completely native. Ran it through exe4j to get a nice little binary launcher and I was in business.

The only dramas I had was getting the form icon to look right (there still seems to be some issues with PNG transparency and SWT on Windows, and I couldn’t really be bothered converting things to GIFs so I’m just living with it).

So my take is that I’m ditching Swing and running with SWT for all further GUI jobs. The Layout managers are great, the widgets are native (and have simple APIs that I could use mainly from autocomplete), and the doco is abundant.

More info here when my experience grows, and my mid-sized project gets the facelift that I’ve been putting off. I gotta say, though, after my first experiences of a small port, SWT just gets me excited about the desktop again!

About the Author: Glen Smith

13 Comments + Add Comment

  • I had the same feeling when i started using SWT. The things are pretty much easy in SWT. The only problem is when come to something when need to create some thing like a database designer or a work flow editor (similar to GEF) i have been hanging on eclipse.org news group but didnt find any help from them either. Also one superiority that SWT has over Swing/AWT is the interaction from user. The GUI is quite fast and ther is no degradation in performance also.

  • It’s not so bad for a couple af buttons, but for the real things I prefer Swing.

    Try to make something like looking over the combo while you are typing in it with sync to some table…

    First you have to look over all the combo items to find which item to select… then to find one in a table.

    Without MVC you always need to keep a copy your data.

    In swing I can make the same model for both list and table (as well as a renderer) so once I type a key I search over collection (my model can implement comparable) and once I got it from list I have the OBJECT not the index or some text represention…

    About the renderer – few days ago I’ve been asked to make JList and JTable to have the same colored info. Can you put it in Combo in SWT? I can easy put an html in ListRenderer and (I as I told before reuse the same class for both!!).

    SWT just looks to be easy for the small project, but after while I came back to swing. One thing I hate in swing is a SUN policy that doesn’t permit to complile it with excelsior jet compiler, So if you need JRE-less Java application – it’s the only way to go. And OLE integration in SWT (for win) is easy enough.

  • There are some swing samples at sandraSF.com (and MVC code)

    There is … JDNC.

    .V

  • I truely don’t understand the problems
    that people have with swing.
    I’ll wait to see if SWT really makes
    it any farther than AWT did.

    See this article…
    http://www.builderau.com.au/program/work/0,39024650,39176462,00.htm

  • “I’ll wait to see if SWT really makes it any farther than AWT did. See this article…”
    –> You should take a look at this blog:
    http://onthethought.blogspot.com/2005/02/gosling-on-swt.html

    James Gosling’s point of view is obviously biased…

  • Have you tested your app on other OSes? Under X11, SWT is very slow, for example in Eclipse there is a noticable key lag.

  • R U sure? In my experience, SWT is buggy as hell (well i do not say SWING is flawless, but besides the parser which is awful, the rest od the FW is decent).

    SWT is far not so flexible as SWING: Try to put items to a Combo, where every item consists of a picture and formatted text (but there are even more exotic settings). I am sure you can do it somehow (or maybe not so sure) but it is far from being natural (whereas in SWING it is).

    ATM i am developing a browser based on swt.Browser+Mozilla and i have to say that swt.Browser is quite buggy…

    All in all SWT is a nice stuff – but i agree wit ppl that mainly for smaller apps….

  • SWT for smaller apps?
    Huh, how ’bout Eclipse, guys?? It’s a pretty large app, and it does quite well, thank you very much.

    Also, Thinking that SWT is not MVC is ignoring JFace. Granted, Swing uses MVC to a much larger extent, but that’s its failing as much as it is its strength.

    Swing is very good in theory. But for large client apps, it still has not proven that it can deliver (see NetBeans, which is still way too slow to be useful IMHO). So I would reverse the comment made by some people: Swing for small apps, SWT for large ones (esp. with the help of the RCP).

  • “SWT for smaller apps? Huh, how ’bout Eclipse, guys??”
    I agree Eclipse is a hog.. but SWT doesn’t require eclipse. In fact you don’t even need the JRE.. so you can even compile it down to a binary with gcc .. or better yet Excelsior Jet.

    Did I mention no JRE?

  • On the comments on NetBeans. NetBeans 4.0 with JDK 1.5 is so fast I can hardly believe it. I agree that NetBeans < 3.5 on a 1 GHz machine was not so quick, but the new JDK really seems to have helped the speed of Swing apps. I have no complaints with MODERN Swing in performance or model. On deployment, think about the difference between something like JBidWatch and Azureus Bittorrent Client. One download for JBidwatch and you run it with “java -jar”. Azureus has 7 different architectures. 4 Linux targets… OMG! And I couldn’t even get the one for gtk running because my gtk libs were too new. If it weren’t for that downside I’d consider using SWT.

  • I like the Eclipse RCP verry mutch, but it seems to work only well on the Windows platform. For applicatins that have to run on heterogeneous operating systems I think Swing is the better solution.

  • I’m with you man. Check out azureus… piece of cake. (thanks azureus guys!)

  • currently, I really prefer swing because thats what i am use to. … but i have issues with slow startup time, memory usage and some simply things joptionpane dose not operate like its native counterpart … So swt looks like a good alternative… but the though of converting all my forms is painful… i will wait and see if the next version of java will bring any acceptable performance otherwise i will have to convert those forms.

Leave a comment

Glen Smith

About Glen

Co-author Grails in Action