Mac OS X Support

Overview

While Java application built with Java Foundation Classes (JFC) / Swing GUI components are suppose to have the same look the feel on all supported platforms, some adjustments may still be necessary to provide the experience a user expects. On a Mac for instance, application menu bars belong at the top of the screen. Windows users may not know this but the Mac application that currently has the focus integrates its menu bar nicely into the Mac menu bar at the top of the screen. Up there, a couple menu items like about, preferences, and print for instance have designated locations. Then, there is the Mac lingo of course: Mac users quit an application - they do not exit. The Mac OS X comes with Java 1.4.1, which also includes WebStart. Moreover, it contains ui.jar, which has all what's needed to adjust a Java Swing application to look and feel more like a native Mac app.

Details

The SwingEngine detects if it is instanced on Mac OS X and provides a public static getter informing about this:

public static boolean SwingEngine.isMacOSX()

There is also a getter that informs about the state of the support flag. Only if instanced on a Mac and if this flag is set to true, the SwingEngine will render native Mac OS X behavior:

public static boolean isMacOSXSupported()

By default, isMacOSXSupported returns true. However, there is a setter available to toggle Mac support.

MAC Specific Localization

The SwingEngine defines a local variant that can be used to provide a Mac specific lingo, mnemonics, accelerators, etc.

public static final String MAC_OSX_LOCALE_VARIANT = "mac";

For instance if an applications localizable resources are kept in a file like
locale/res.properties, the English / US localization would be stored here:
locale/res_en_US.properties.
In the XML descriptor, the root tag would probably contain these attributes:

bundle="locale.res" locale="en"

Mac specific localization like replacing exitwith quitor more importantly the localization of Accelerators (you may want to replace controlwith metawhen running on the Mac) would need to be stored here:
locale/res__mac.propertiesfor languages/countries independent entries, or
locale/res_en_US_mac.propertiesfor instance for english / US / Mac localizations.

With MacOSXSupportedenabled, the SwingEngine will integrate the
application main menu bar into the Mac's menu bar.
To additionally link an applications Action for AboutBox, Preferences, Printing, etc. with the Mac menu bars's default menu items, Swixml proprietory attributes needed to be added to the menu item tags.

Example

<menuitem name="mi_about" text="mis_About" Action="actionAbout" Accelerator="acc_About" macos_about="true"/>

Attributes to link actions with the Mac menu bars's default menu items:

  1. macos_about
  2. macos_openapp
  3. macos_openfile
  4. macos_preferences
  5. macos_print
  6. macos_quit
  7. macos_reopen

Misc.

When rendered on OSX, any given plaf is ignored and replaced by the MAC's default Aqua L&F. Accelerators and special lingo is read from a resource file, (.._mac.properties), and the public Action implementation is being linked with the Mac specific handleAbout event.

The Mac OS X comes with Java 1.4.1, which also includes WebStart. Moreover, it contains ui.jar,which has all what's needed to adjust a Java Swing application to look and feel more like a native Mac app.
The ui.jar is only used on the Mac where it is already available (at least with Java 1.4.1 update 1). However, to compile the swixml.jar, the ui.jar needs to be in the compile path and therefore has been inserted into lib folder of a swixml distribution.

Summary

Swixml (since release build 130) takes care of all Mac UI specialties without requiring Java code changes. Swixml detects when running on OS X and looks for additional attributes in the XML descriptors.
The seven Mac related attributes are being ignored on all other platforms.
One additional resource file and flagging a couple actions with an attribute are all what's needed to give a Swixml powered Java application a more native Mac look and feel. Make use of it.

Swixml rendered GUI on Windows...


...same Swixml rendered GUI on Mac OS X: