Alternatives to Swing

Hey,

I have googled for this a little and found results here and there, but nothing, that truely satisfies me.

I am looking for a GUI library for Java, that offers two main requirements.

  1. It should have a nice and modern API design
  2. It should not be implemented in software all along, but make use of platform specific native GUI calls as much as possible.

Theming is one thing, but in 99% of all cases you will want to make your application look like any other app on your platform. So a button should look like a button on KDE or Win 7 or what ever you’re running the application on. So by default the GUI should look and behave like any other app on your platform and optionally and less importantly there COULD be the ability to theme it.

Controls like JTable or JTree are very powerful, but simply suck. I love the model approach and you can easily implement a default table with default renderers/editors and event handling. But when you want something more complex, it starts to stress you with unexplainable malfunction, which costs a lot of time to fix or to workaround.

A modern API should make use of enums instead of static int constants. This is much easier and intuitive to use.

Of course the API must be platform independent. So there have to be native libraries for all supported platforms, so that as much of the drawing as possible can be done by the windowing system natively. When a button is created, this shouldn’t mean to let Java paint a button, that looks like a platform specific one, but this should ask the platform to create a native button. This applies to all controls, that are supported by the platform. The unsupport ones would have to be rendered in software mode. This makes sure, that the GUI is as responsive as any other app on your platform, but doesn’t suffer from slower software mode.

Of course a library like this would have to replace AWT/Swing as a default in the JRE/JDK, so that all the needed natives can be shipped with it and it would be usable in an applet or Java web start.

What do you say? Is there something like this out there?

Marvin

SWT http://www.eclipse.org/swt/docs.php

Theres also QTJambi http://qtjambi.sourceforge.net/ , doesn’t get more native looking then this toolkit (Even integrates nicely with KDE). Also has a host of really powerful tools and editors.

JTable and JTree aren’t half bad when you figure out the bits of voodoo you need to do to make them work nicely.

Cas :slight_smile:

Yeah, the MVC makes these controls delgate everything. It just takes a bit of hunting to find the correct delegator to override to make them do what you want.

And a few hacks and tweaks and overrides and putClientPropertys. But it’s all good in the end.

Cas :slight_smile:

Yes. Actually, it has some nice platform-specific bugs especially in the drag and drop gesture on Linux ;D

For desktop apps I really like SWT: http://www.eclipse.org/swt/
SWT calls the native api so it looks/feels/works like a native app

For games (open gl base), TWL is really nice: http://twl.l33tlabs.org/
TWL is themeable, you can do just about anything with it.
It’ll look/feel the same on all platforms (which is probably want you want for a video game)

TWL does look very good.
Also consider PureSwing.

Cas :slight_smile:

Could do a front end in JavaFX to build the GUI.
But of course it will look the same on every OS, but who know’s there could be theme libraries to solve this.

'zactly. Those are incredibly flexible classes - it just takes a wee while to figure out how they work internally when you want to do custom cell editors or renderers.

The last line crashes the JVM on Linux because SWT calls the win32 native method instead of calling the Linux method in ImageTransfer.nativeToJava(TransferData data):

final PaletteData palette =  new PaletteData(0x0000FF, 0x00FF00, 0xFF0000);
final ImageData imgData = new ImageData(256,256, 24, palette);
final Clipboard cb = new Clipboard(getDisplay());
ImageTransfer imageTransfer = ImageTransfer.getInstance();
cb.setContents(new Object[]{imgData}, new Transfer[]{imageTransfer});

It is not serious! calling a native method for Windows on Linux!
This is an example of bugs that shows SWT is not reliable especially on Linux. This bug has already been reported and has never been fixed… I know some other bugs of this kind (I have to close Klipper on some Linux machines otherwise the drag and drop of text does not work in Eclipse, do you want some more?). That is why I don’t advise SWT. Maybe have a look at PureSwing.

I’m sorry to insist on this but Marvin Fröhlich seems to be looking for a cross-platform library.

It’s a bit much to eliminate SWT because it has a bug or two. Better to eliminate it because it is difficult to extend if you want functionality beyond what is provided out of the box.

No, there are more than 2 bugs that are specific to Linux in SWT and the most used workaround often consists in mixing SWT with AWT… which might cause some other problems.

I agree with you.

Thanks a lot, guys, for these very detailed answers.

Yes, I am looking for a cross platform library, that doesn’t look the same on all platforms, but makes use of native components and hence looks like a native app with the locally selected theme or what ever.

I am not a big fan of SWT neither. It has an ugly API and doesn’t work too well on Linux. I once ranted the Eclipse devs, that they don’t care for Linux too much and Eclipse works a lot better on Windows. Maybe it wasn’t fair, but it was and is true.

Perfect would be something like SWT with a nice and modern API and with less platform specific bugs.

I will have a look at PureSwing. I didn’t know that one.

Marvin