Thursday, January 04, 2007

Disappointing Swing

Wrote yet another small utility today.

Since I wanted to reuse a lib written in Java I decided against a the most productive OO System and also came over other temptations. Call me nuts but I wanted to build the user interface in Java with Swing...

I had installed the "Java Mustang" (JDK 1.6 release) last month to play with the new Scripting support (Java now includes the Rhino JavaScript implementation). So I had the latest and greatest Swing on my machine - time for Desktop Java. At that time I was also eager to play with the promised new Desktop integration. Unfortunately this "integration" was nothing more than open the web browser, open mail, and open/edit a document with the associated program. Something the Win32 API had since the days of the ShellExecute() function. But that's another story.

Back to my little Swing utility: I started Eclipse since the IDE supports Swing, SWT and AWT GUI building with the VisualEditor project.

I easily generated a simple JFrame window together with some code for a simple application menu. Some typing here, some coding there I managed to complete my small tool. Work was done so I decided to beautify the UI.

First I switched to the correct Windows L&F since the tool is used "Win only":

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel")

After that I wanted to add icons to the menu items. So I imported a gif into a package and added it as menu icon resource using the property palette.

When I hit the "Run" button I was surprised that the image was too close to the text.



What a waste of space on the left side. I think it is intended for menu items with check boxes (JCheckBoxMenuItem) and an additional image. But I have no checked menu item here. Also not very "winlike". I would have expected something like this (screenshot from a native application):



I played with setHorizontalTextAlignment() to align the text to the right. But the situation got worse:



The image disappeared. Time for Google: Ahhh - Bug 6385358
revealed it: in JDK 1.5. the text overlaps the shortcut text and in the latest Mustang build, ONLY the shortcut text appears (without the menu item text).

The bug was submitted 14-FEB-2006 and in 2007 it is still in progress! Maybe they have to fix the other 222+221+216+214+213+211+210+29+27+26+23+22+20 bugs first.

How sad - have to move on without menu icons or switch to SWT. Very disappointing! Anything I wanted was a simple windows like UI in Swing ...

No comments: