I recently started work with the Eclipse IDE, which mentions SWT. What's the difference between Swing and SWT? Is there an advantage of one over the other? Is SWT going to be used more in the future than Swing? Thanks, Landon
SWT is far superior to AWT/Swing. It takes the look and feel of the Operating System instead of a fixed motif. If you change the look and feel of your Windows OS, the look and feel of your components would accordingly change. Above all it is much faster than Swing. Basically you would not believe in first instance that your Java application can look like any windows GUI !!
I wouldn't say that SWT is superior, but is is a nice option. The biggest advantage that SWT has over Swing is that it does look exactly like a native GUI. I have also noticed a noticeably faster startup time for SWT apps over Swing apps, and SWT is also noticably more responsive on low-end windows machines than Swing. However, on high end machines, there is really no noticable difference, and some people have complained that SWT is slow on Linux (though I haven't given this a try recently myself... it may have improved).
As far as the programming model, I tend to prefer Swing... this is probably mostly just a personal bias, as I have used Swing much more than SWT, but SWT has a couple of features that are annoying to me. SWT requires you to explicitly destroy native resources that your application uses... this includes things like colors, fonts, and components. Some things are automatically handled for you, like child components are destroyed when you destroy a parent component. But others, like colors and fonts, require you to either destroy them yourself when you are done with them, or use a listener interface to destroy them when another specific component is destroyed. SWT layouts are also annoying. Almost every layout requires a specific layout helper class to be attached to the components to be layed out. Unfortunately, these are all treated as plain Objects, so if you change layouts but forget to change all the layout helpers, everything compiles fine, but you get a runtime class cast exception. Also, all child components have to have their parent component passed into their constructor, which is annoying compared to dynamically moving components around by add()ing them to different containers in Swing.
However, SWT is still evolving... it is still very new, and it is open source, so there are many sources where this change can come from. For now I mostly use Swing, but there are some cases, such as if one of the advantages I mentioned at the start of the post are very important requirements, where I would use SWT.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Is there any good open source application besides Eclipse itself demonstrating SWT technique of programming. I have Swing app and although it performs quite well (I consider faster than native one), it's still lacking in too Javish L&F making user think that they use "crappy" Java.
Originally posted by D Rog: Is there any good open source application besides Eclipse itself demonstrating SWT technique of programming. I have Swing app and although it performs quite well (I consider faster than native one), it's still lacking in too Javish L&F making user think that they use "crappy" Java.
If that is your only problem, rather than trying to convert you app, why don't you apply a Look and Feel of your own? Or better yet, use something like JGoodies Looks. The Looks L&F is really sharp and performs really well. They even have a Windows XP L&F that performs better than JDK 1.4's Windows XP L&F. Also, you could use Java 1.5 which has a new L&F that looks quite a bit better than the Metal L&F that Java used to default to.