The Source for Java Technology Collaboration
User: Password:



Kirill Grouchnikov

Kirill Grouchnikov's Blog

Aligning menu items in Swing applications - welcome to the real world

Posted by kirillcool on February 18, 2006 at 12:53 PM | Comments (8)

When i have written the previous entry on aligning menu items in Swing applications, i was blissfully ignorant and thought that the life was good. Thankfully, one of the users of Substance has opened this defect with the following summary - "Menu texts are invisible in RTL orientation".

Why, say you. What's that RTL has to do with my application? Turns out that there are four locales that define the right-to-left orientation (who should know better than me...), Arabic (ar), Hebrew (iw), Persian (fa) and Urdu (ur). Under these locales, the users expect their applications to be layed-out correspondingly. Swing core look-and-feels provide quite a good support for this:

These two screenshots of Metal in Tiger and Metal in Mustang (you can see that Mustang properly aligns the texts, but fails quite miserably at aligning the accelerators):



The same problem with the accelerator alignment on RTL menus under Mustang is with the Windows LAF:



And what happens with the third-party LAFs you ask? Well, it depends. Here's a short chart of nine third-party open-source and commercial LAFs sorted by the degree of current RTL support in the menus (both under Tiger and Mustang):

  • The first place - JGoodies' Looks. The only problem is with the accelerator alignment (both on Tiger and on Mustang). The first place doesn't come easy though - JGoodies provides its own layout and painting mechanism and as such, it uses the SwingUtilities2 class which is unsupported. Hence, this ungodly creature in the codebase of 2.0beta:
        private static final String SWING_UTILITIES2_NAME =
            LookUtils.IS_JAVA_6_OR_LATER
                 ? "sun.swing.SwingUtilities2"
                 : "com.sun.java.swing.SwingUtilities2";
    
    The screenshots for Tiger and Mustang (note the accelerator alignment problem which is better in Mustang but still slightly off - this has been fixed for Beta2 coming in the next few days):

  • The second place - Substance (would have been sixth and the last place yesterday). Both under Tiger and Mustang properly aligned texts, but the accelerators are off. The main hindrance to getting this to work (not only in Substance but also in all other Metal-extending LAFs below) is that the UI delegates for menu items do not provide hooks for painting the accelerators. The only available way is JGoodies way - do it yourself (and be bound to use SwingUtilities2). The screenshots for Tiger and Mustang (note the accelerator alignment problem present in both):

  • Third place - Pagosoft, Squareness and Napkin. In addition to the accelerator alignment as above, the texts aren't aligned under Tiger (core fix in Mustang). The screenshots of Pagosoft for Tiger and Mustang (note the text alignment under Tiger):



    The screenshots of Squareness for Tiger and Mustang (note the text alignment under Tiger):



    The screenshots of Napkin for Tiger and Mustang (including Tiger workaround for this bug fixed in Mustang):



  • Fourth place - Synthetica (commercial) and Trendy (commercial). In addition to the accelerator alignment and text alignment under Tiger, the arrow points to the right and not to the left. The screenshots of Synthetica for Tiger and Mustang (note the arrow direction):



    The screenshots of Trendy for Tiger and Mustang (note the arrow direction):

  • Fifth place - Liquid and Tiny. The RTL menus are completely messed up both under Tiger and Mustang. Screenshots of Liquid and Tiny under Mustang:

  • Sixth place - Office (and Substance yesterday). No support at all for RTL menus - the menus are layed out left-to-right. Screenshot under Mustang:

The above support for RTL menus in Substance is available in the release candidate of version 2.2. In addition, the version 2.3 will provide full support for RTL features (including additional UI elements that Substance adds). Great thanks to the reporter that made me finally think of this and let's hope that the accelerator alignment issue will be addressed in the final release of Mustang.

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • (w.r.t. NapkinLAF)
    Ouch - looks like I'd better fix that, but...
    Where did that arrow come from? I mean, if you look at here you should see a customised arrow for submenus...
    Anyway, which build of NapkinLAF were you using for your screenshot? ;-)

    Posted by: alexlamsl on February 21, 2006 at 10:28 PM

  • For Napkin it's 1.0 beta 005.

    Posted by: kirillcool on February 21, 2006 at 10:37 PM

  • Hi Kirill, the layout and painting mechanism in JGoodies Looks is not bound to SwingUtilities2! SwingUtilities2 has nothing to do with the RTL problem. We use SwingUtilities2 only to paint strings. If SwingUtilities2 can not be accessed, we provide the fallbacks. If you like to understand the motivation behind the usage of SwingUtilities2, please, read the comments on the issue #69.-Andrej

    Posted by: golovnin on February 22, 2006 at 12:10 AM

  • Andrej,
    The original intent of the sentence was - JGoodies has its own layout and painting mechanism for the menus (in the menu renderer class). This mechanism (among the rest) uses SwingUtilities2 class to paint the menu text. It is correct that there's a fallback mechanism, but the use of SwingUtilities2 is still there. The lookup of the package name can be slightly better though - for Java 6 it has changed in the middle (i think from b61 or b62).

    Posted by: kirillcool on February 22, 2006 at 12:17 AM

  • Having this fixed is useful for more that 4 locales. I just recently finished up a Java Applet for Tablet PC deployment and dealt heavily with this problem.

    On a tablet, when "writing" with your right hand, having menus pop under your hand is tedious and difficult, being able to "right-align" the menus would be helpful.

    It'd be great to have some integration (JDNC?) to detect that the device is a tablet, render the menus RTL (with a non-RTL locale) and have everything render correctly.

    Posted by: mawcs on February 22, 2006 at 10:42 AM

  • Fixed in NapkinLAF - thanks for reporting ;-)

    Posted by: alexlamsl on February 22, 2006 at 02:41 PM

  • Alex,
    Is there a binary drop available to test and fix the screenshot?

    Posted by: kirillcool on February 23, 2006 at 02:59 AM

  • I'm currently working on a few other issues, but if you want to I can send the latest build to you~

    Posted by: alexlamsl on February 23, 2006 at 08:06 AM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds