aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Swing versus SWT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing versus SWT" Watch "Swing versus SWT" New topic
Author

Swing versus SWT

Landon Blake
Ranch Hand

Joined: Dec 04, 2003
Posts: 121
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
Mrityunjay Prasad
Greenhorn

Joined: Jan 21, 2004
Posts: 4
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 !!
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Al Kaiser
Ranch Hand

Joined: Nov 20, 2003
Posts: 35
But, is it possible to port Swing applications(i.e.,already written in Swing) to SWT?
Sreenivasa Majji
Ranch Hand

Joined: Jul 12, 2001
Posts: 224
Currently there is no tools available for swing to swt conversion. Infact there is no decent editor for SWT.


Sreenivasa Majji
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

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.


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
 
 
subject: Swing versus SWT