tags:

views:

77

answers:

3

I am really confused over what to use. Options I see are awt, Swing and swt.

My question is which should be best for Desktop Java app on all platforms( Mac,Windows and Linux )with minimum platform dependent code ?

+5  A: 

Swing.

AWT is old and too low-level, SWT has native components, and doesn't ship with the JRE (it's a third-party library). Swing is high-level (-ish), and pure-java.

skaffman
Perhaps include the fact that Swing is available in all java runtimes for the desktop, but that SWT requires external dependencies.
extraneon
@skaffman Could you please add some more information why one should not use SWT? Its not clear to me. Im usig it and I don't have problems so far.
InsertNickHere
@InsertNickHere - just wait until you have more than Windows to deploy to :)
Thorbjørn Ravn Andersen
A very good note on Swing design: http://www.jgoodies.com/freeware/metamorphosis/index.html
Thorbjørn Ravn Andersen
@InsertNickHere: As I said, SWT is not pure-java, it requires native libraries. The question wanted minimal platform dependencies.
skaffman
+1  A: 

I would go with Swing as the best choice using what's packaged with Java. However, even Swing can make you jump through all the same hoops every time, so I would recommend looking into one of various frameworks that build on top of it and handle most of the boilerplate work of building an app.

There's a JSR for a Swing Application Framework which I have used when it was still in active development, but it's currently frozen. Their project page recommends a fork of that project, and another one called GUTS which uses Google Guice as its dependency injection. Netbeans also has Netbeans Platform.

I know the scope of these frameworks goes outside the realms of "UI", but they handle things like data-binding between your model and your UI which Swing does not do.

Nick
+5  A: 

AWT is obsolete, though some of its classes and design form the underpinnings of the Swing API.

Here is my take on the differentiators between creating applications in Swing and SWT:

Swing

  • + Forms part of the standard Java-SE platform, so fewer distribution headaches
  • + You can create a consistent look and feel across platforms
  • + Controls are lightweight, so creating your own is relatively easy
  • - If you need Swing applications to look like native applications, there may be a lot of work in it; Swing can be styled with a platform look'n'feel, but the results aren't always close enough for everyone's satisfaction

SWT

  • + Easy to create simple applications which use native widgets
  • - Manual resource management
  • - You need to distribute platform-specific libraries
  • - You face the lowest-common-denominator problem - not all widgets are available on all platforms, so some will be custom to SWT anyway

Although I've put a lot more minuses against SWT, I wouldn't discount it. Which technology you pick will depend on your project requirements. Picking the library is only the beginning when it comes to UI development.

Swing is the easy, low-maintenance option and I'd agree with the other posters that this is probably the best fit for what you want.

McDowell
what about `UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());`?
Tedil
@Tedil - Swing has come a long way with support for native LnFs (esp. since 6u10), but if your UI designer insists on perfect integration you may have to work around the bugs. Some people are extraordinarily persistent in bugging you if the something is one pixel out or the anti-aliasing algorithm produces a slightly different type of blur. You can track such problems in the bug database: http://bugs.sun.com
McDowell