Java GUI Frameworks - which are out there? [closed

2019-01-18 05:05发布

问题:

I mainly developing Java EE and now I'm in a situation where I need to write a small native Java app.

But tbh I'm a little bit lost, which frameworks (Swing, SWT, etc.) are out there? Is some rapid dev also possible with one of these? Maybe someone could provide me some links or share his experiences.

回答1:

Swing and SWT are the two main candidates, yes. JavaFX also comes to mind, but I think it's not yet ready for prime time: it had no UI editing tool worth speaking of for a long time, the only enterprise UI prototype I know of in real life was a fiasco...

Swing and SWT are the two you might think about. Swing's basic advantages are:

  • more platform independent
  • more consistent in terms of performance
  • better free UI designer (NetBeans)
  • extremely flexible
  • can be used in JavaFX

SWT's advantages are:

  • simpler API
  • uses native UI widgets when it can (the UI is more similar to other apps in the same environment)
  • at some point, it was argued that it's faster than Swing, although this was on Windows only

Quite advanced rich client frameworks exist for both (NetBeans Platform and Eclipse RCP) and if you plan on building anything non-trivial, I would heartily suggest you use one of these: you get modularized apps, update mechanisms, context-sensitive help, consistent actions over menus, hotkeys and toolbars, window management and lots of other excellent features for free.

I worked with Swing and prefer it over SWT as it has a purer component model (with SWT you have to worry about freeing resources, as you're using native widgets), is truly multi-platform (SWT works on Windows, MacOS and Linux, and is not even very well optimized for all three), and it's more customizable.

You're probably not making a mistake trying SWT or even JavaFX, but I'd be hard-pressed to find a good reason to switch to SWT and would try JavaFX only to check the state of the art, assuming the app is just a showcase app.

I could sprinkle a couple of links, but you can easily search for yourself and find the results than interest you.



回答2:

There are also GUI frameworks that are not written in Java which might serve your purposes. For example, GTK+ is written in C but there are language bindings to Java. Check out java-gnome for example.

I don't know how good it is, but a quick Google search also turned up Java bindings for Qt so maybe that's also worth looking into.



回答3:

I had a similar thing to do a while back. I finally settled on Swing App Framework because it does not try to be the one framework to rule them all.

In the end I wrote the little app, had no surprises, the code turned out to be pretty clean (including uploading in a ackground task), the customer is happy, I am happy.

It aims to provide (stolen from the blurp)

  • Application lifecyle, notably GUI startup and shutdown.
  • Support for managing and loading resources, like strings, formatted messages, images, colors, fonts, and other types common to desktop applications.
  • Support for defining, managing, and binding Actions, including Actions that run asynchronously (in the "background").
  • Persistent session state: support for automatically and selectively saving GUI state from one run of an application to the next.

which was exactly what I needed.

Warning: there appears to be little life in this framework as the driving force is rumored to have left Sun/Oracle a while back.

Update: some devs have forked in Project Kenai under the name 'Better Swing Application Framework'. So there may be life after death after all



回答4:

Take a look at Apache Pivot. It is meant to be a higher level more modern framework than just plain Swing, that still uses Java instead of going all the way to JavaFX. It positions itself as an RIA toolkit, but it can just as easily be used for standalone desktop apps. From the website:

Apache Pivot is an open-source platform for building rich internet applications in Java. It combines the enhanced productivity and usability features of a modern RIA toolkit with the robustness of the Java platform. Pivot applications are written using a combination of Java and XML and can be run either as an applet or as a standalone, optionally offline, desktop application. [...] Pivot includes additional features that make building modern GUI applications much easier, including declarative UI, data binding, effects and transitions, and web services integration.



回答5:

I think JavaFX is a good choice because it has a good UI and all features of Swing



回答6:

The free NetBeans IDE has a visual layout tool for both Swing and JavaFX.



回答7:

GWT can also be great UI tool for java based application.As code done in GWT is same as Java code.Another thing is GWT its own handle browser compatibility.It has rich widgets factory,internationalization,security and many more features.



回答8:

i recommend against using a layout tool; the code is very hard to read and maintain.

also, if you need database access to objects, then netbeans will leave entity managers open and create major headaches and bugs later if your app needs to use more than one thread.