tags:

views:

2478

answers:

8

Hey,

I'm a web developer at day and thinking about building my first real desktop application. The idea is to build a tool that automates a very repetitive task in a web application where no API is available.

I know I want to use Java. I used it before for web stuff, know the syntax pretty well and want the application to be cross plattform as easy as possible.

Where I'm not so sure is if I should use SWT or Swing. As my main audience uses Windows, I want to look it as native as possible there. Linux and Mac should work, but the looks are not so important here.

So what are the arguments for and against each UI Framework, Swing or SWT?

Thanks.

PS: I develop on Windows using Eclipse. But was thinking about playing with Netbeans.

+2  A: 

For your requirements it sounds like the bottom line will be to use Swing since it is slightly easier to get started with and not as tightly integrated to the native platform as SWT.

Swing usually is a safe bet.

Yuval A
+3  A: 

Interesting question. I don't know SWT too well to brag about it (unlike Swing and AWT) but here's the comparison done on SWT/Swing/AWT.

http://www.developer.com/java/other/article.php/10936_2179061_2/Swing-and-SWT-A-Tale-of-Two-Java-GUI-Libraries.htm

And here's the site where you can get tutorial on basically anything on SWT (http://www.java2s.com/Tutorial/Java/0280_SWT/Catalog0280_SWT.htm)

Hope you make a right decision (if there are right decisions in coding)... :-)

The Elite Gentleman
+1  A: 

I whould choose swing just because it's "native" for java.

Plus, have a look at https://swingx.dev.java.net/.

zeroed
+9  A: 

pro Swing:

  • part of java library, no need for additional native libraries
  • works the same way on all platforms
  • Integrated GUI Editor in Netbeans
  • good online tutorials by sun
  • Supported by official java extensions (like java OpenGL)

contra Swing:

  • Native look and feel may behave different from the real native system.
  • heavy components (native/awt) hide swing components, not a problem most of the time as as use of heave components is rather rare

pro SWT:

  • uses native elements when possible, so always native behavior
  • supported by eclipse, gui editor VEP (VEP also supports Swing and AWT)
  • large number of examples online
  • has an integrated awt/swt bridge to allow use of awt and swing components

contra SWT:

  • requires native libraries for each supported system
  • may not support every behavior on all systems because of native resources used (hint options)
  • managing native resources, while native components will often be disposed with their parent other resources such as Fonts have to be manually released or registered as dispose listener to a component for automatic release.
josefx
Swing will be closer to "write once, run anywhere". SWT will be more like "write once, tweak/test everywhere". But this same discussion happened with other languages as well.
Mark
+9  A: 

An important thing to consider is that some users and some resellers (Dell) install a 64 bit VM on their 64 bit Windows, and you can't use the same SWT library on 32 bit and 64 bit VMs.

This means you will need to distribute and test different packages depending on whether users have 32-bit or a 64-bit Java VM. See this problem with Azureus, for instance, but you also have it with Eclipse, where as of today the builds on the front download page do not run on a 64 bit VM.

Ludovico Fischer
Interesting point. As a user I'm still staggered why this is such a big deal. But well, it is so I will have to consider this. Thanks.
Jan P.
good point, +1 for the info.
posdef
+2  A: 

If you plan to build a full functional applications with more than a handful of features, I will suggest to jump right to using Eclipse RCP as the framework.

If your application won't grow too big or your requirements are just too unique to be handled by a normal business framework, you can safely jump with Swing.

At the end of the day, I'd suggest you to try both technologies to find the one suit you better. Like Netbeans vs Eclipse vs IntelliJ, there is no the absolute correct answer here and both frameworks have their own drawbacks.

Pro Swing:

  • more experts
  • more Java-like (almost no public field, no need to dispose on resource)

Pro SWT:

  • more OS native
  • faster
nanda
I think the "faster" point is highly contentious.
Russ Hayward
+3  A: 

I would use Swing for a couple of reasons.

  • It has been around longer and has had more development effort applied to it. Hence it is likely more feature complete and (maybe) has fewer bugs.

  • There is lots of documentation and other guidance on producing performant applications.

  • It seems like changes to Swing propagate to all platforms simultaneously while changes to SWT seem to appear on Windows first, then Linux.

If you want to build a very feature-rich application, you might want to check out the NetBeans RCP (Rich Client Platform). There's a learning curve, but you can put together nice applications quickly with a little practice. I don't have enough experience with the Eclipse platform to make a valid judgment.

If you don't want to use the entire RCP, NetBeans also has many useful components that can be pulled out and used independently.

One other word of advice, look into different layout managers. They tripped me up for a long time when I was learning. Some of the best aren't even in the standard library. The MigLayout (for both Swing and SWT) and JGoodies Forms tools are two of the best in my opinion.

clartaq
+2  A: 

pro swing:

  • The biggest advantage of swing IMHO is that you do not need to ship the libraries with you application (which avoids dozen of MB(!)).
  • Native look and feel is much better for swing than in the early years
  • performance is comparable to swt (swing is not slow!)
  • NetBeans offers Matisse as a comfortable component builder.
  • The integration of Swing components within JavaFX is easier.

But at the bottom line I wouldn't suggest to use 'pure' swing or swt ;-) There are several application frameworks for swing/swt out. Look here. The biggest players are netbeans (swing) and eclipse (swt). Another nice framework could be griffon and a nice 'set of components' is pivot (swing). Griffon is very interesting because it integrates a lot of libraries and not only swing; also pivot, swt, etc

Karussell