Java Desktop application: SWT vs. Swing [closed]

2019-01-04 05:21发布

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.

标签: java swing swt
10条回答
Viruses.
2楼-- · 2019-01-04 05:32

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

查看更多
一夜七次
3楼-- · 2019-01-04 05:32

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.

查看更多
地球回转人心会变
4楼-- · 2019-01-04 05:40

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.

查看更多
做自己的国王
5楼-- · 2019-01-04 05:41

One thing to consider: Screenreaders

For some reasons, some Swing components do not work well when using a screenreader (and the Java AccessBridge for Windows). Know that different screenreaders result in different behaviour. And in my experience the SWT-Tree performs a lot better than the Swing-Tree in combination with a screenreader. Thus our application ended up in using both SWT and Swing components.

For distributing and loading the proper SWT-library, you might find this link usefull: http://www.chrisnewland.com/select-correct-swt-jar-for-your-os-and-jvm-at-runtime-191

查看更多
戒情不戒烟
6楼-- · 2019-01-04 05:45

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

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

查看更多
神经病院院长
7楼-- · 2019-01-04 05:47

SWT was created as a response to the sluggishness of Swing around the turn of the century. Now that the differences in performance are becoming negligable, I think Swing is a better option for your standard applications. SWT/Eclipse has a nice framework which helps with a lot of boiler plate code.

查看更多
登录 后发表回答