Every once in a while i get questions on using the Mac OS X menu bar for Swing applications running under Substance look-and-feel. This refers to the apple.laf.useScreenMenuBar VM flag that is respected by the native Aqua look-and-feel (and its third-party Quaqua extension). Up until this week the only advice that i could give was to use AWT menus (thanks to Quaqua’s author Werner Randelshofer for this). However, it is not the optimal solution for cross-platform Swing applications that wish to use Swing menus on non-Mac platform.
As i was thinking about this problem after being recently contacted by Sergiy Michka, i thought about an alternative solution which was later reviewed by Swing lead for Apple VM Mike Swingler. The solution is not specific to Substance and should work under other core and third-party look-and-feels that allow mixing menu UI delegates from other look-and-feels. Here is what you can do in your Swing application to have your menus appear on the global menu bar (in addition to setting the above VM flag):
- Check that you’re running under Apple VM. Use
<font color="darkblue">System.getProperty("os.name")</font>
and check that the value starts with “Mac”.
- Set Aqua (or the future default Apple VM platform look-and-feel) with
<font color="darkblue">UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())</font>
.
- Query and store the following
<font color="darkblue">UIManager</font>
entries: “MenuBarUI”, “MenuUI”, “MenuItemUI”, “CheckBoxMenuItemUI”, “RadioButtonMenuItemUI”, “PopupMenuUI”.
- Set your look-and-feel of preference with
<font color="darkblue">UIManager.setLookAndFeel</font>
call.
- Before creating your first window, restore the
<font color="darkblue">UIManager</font>
entries for the keys specified in the third step.
Now the menus on the fronted frame will go into the global menu bar. It is not recommended to rely on the current class names for the Aqua UI delegates, since the package that hosts these classes is different for different versions of Apple VM. This is mentioned in the release notes for Apple VM 1.6.0 on Mac OS X 10.5 Leopard (radar #4907470).
Here are some Swing links that you might have missed during this week:
- Kaushik Sathupadi writes about implementing mouse gestures in Swing. Personally, i haven’t found mouse gestures to be overly useful until now, but your users might have a different opinion.
- Danny Coward, Ken Russell and Richard Bair host the “Ask the Experts” session this week on 6u10 over at SDN. Last year Two years ago i wasn’t too lucky and my questions were screened out, but things may change this year.
- Michael Gvirtzman has a new Swing application called “Golden Rules”. It allows several planning levels, actual effort tracking, mind mapping, and contact management, providing function-rich goal system for both beginners and professionals and uses SwingX.
- JavaSwing.net has a short tutorial on InputVerifier, including background on relevant scenarios and sample code.
- Business Swing applications don’t have to be ugly (especially if you’re willing to depart from Metal / Ocean), as the new round of Palantir screenshots shows.
- Clemens Eisserer is one of the chosen finalists for the OpenJDK Innovators’ Challenge with his proposal for implementing XRender pipeline for Java2D. You can follow his blog to track the progress, and this week he announced that the project itself will be hosted at java.net.
- Greg Brown has posted the second part of a practical introduction to the new Pivot UI framework.
- Matt Fletcher writes about his experiences in rolling a JRuby desktop application.
- On a related topic, Mario Aquino has two new screencasts on desktop JRuby libraries. The first screencast is on Cheri and the second screencast is on Monkeybars.
Here are some Swing links that you might have missed during this week:
- Alexander Potochkin shows how to use the new JXLayer to provide mouse auto-scrolling functionality. I have reviewed the available techniques in an earlier post, and this is yet another illustration of the capabilities of JXLayer.
- Jeff Friesen has an article that shows how use animated Windows cursors (in.ani format) in Swing applications. This builds on his previous article on extracting images from the Windows .ico files.
- Reginald Stadlbauer writes about the new release 3.4 of Squish automated GUI testing tool. View the release notes for the new functionality.
- Luan O’Carroll outlines his planned contributions to SwingLabs project. The contributions mainly focus on desktop publishing packages functionality, allowing support for different text flow modes.
- A new article on JavaSwing.net has a short overview on Swing threading and SwingWorker class.
- Finally, Alexey Utkin has released version 0.2.2 of JDICPlus that features native IDE drawing support for PDF, Microsoft Office (Word, Excel, Outlook) and Flash.
Ayman Al-Sairafi has a very useful project called JSyntaxPane which provides syntax highlighting capabilities for the JEditorPane Swing component, supporting Java, XML, Groovy and JavaScript. I’ve already mentioned this project on the latest “Swing links of the week”, and this week i’ve integrated it into the Rainbow SVG file viewer.
Rainbow is a testbed for integrating various desktop projects and building an SVG browser for both local and remote (SVN) repositories. Instead of reinventing the wheel, it uses third-party libraries for the various UI building blocks. Here is the list of the libraries:
- Apache Batik for parsing and transcoding the SVG format.
- Flamingo for the breadcrumb bar, command button and command button panel components.
- Substance for the look-and-feel.
- JXLayer for the spotlight search functionality and applying effects before saving as image.
- JHLabs filters for applying effects before saving as image.
- SVNKit for working with SVN repositories.
- FormLayout for the layout of the top bar and status bar.
- JSyntaxPane for highlighting the XML and Java2D content.
When you click on any SVG icon, Rainbow shows three views of that icon. The first view shows the original SVG XML content, the second view shows the transcoded Java2D class, and the third view allows applying a number of filters and save the image. The JSyntaxPane comes in handy for the first two views – Rainbow now shows the XML and Java2D content with applied syntax highlighting.
Here is a screenshot of the XML content (click for the full view):

and here is a screenshot of the Java2D class (click for the full view):

The JSyntaxPane is available under Apache 2.0 license.