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.
The SwingEngine detects if it is instanced on Mac OS X and provides a public static getter informing about this:
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:
By default, isMacOSXSupported returns true. However, there is a setter available to toggle Mac support.
The SwingEngine defines a local variant that can be used to provide a Mac specific lingo, mnemonics, accelerators, etc.
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:
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.properties
for languages/countries
independent entries, or
locale/res_en_US_mac.properties
for 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.
Attributes to link actions with the Mac menu bars's default menu items:
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.
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.