Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing versus SWT

 
Landon Blake
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Al Kaiser
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, is it possible to port Swing applications(i.e.,already written in Swing) to SWT?
 
Sreenivasa Majji
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently there is no tools available for swing to swt conversion. Infact there is no decent editor for SWT.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic