26.1 Mac OS X and the Default Look-and-Feel


On most platforms, unless the user or application has explicitly specified otherwise, Swing uses the Metal cross-platform L&F, and developers have likely become accustomed to this. With the advent of Mac OS X (which includes a tightly integrated Java environment that tracks Sun's latest releases), things change slightly. Mac users have strong expectations about the appearance and behavior of their applications, and Apple intends Java to be a first-class development environment on its OS. Because of this, the Mac L&F is the default under Mac OS X. This L&F allows Java applications to appear and behave like other Macintosh applications. This makes them more likely to be familiar to and adopted by Mac users.

As long as developers have made good use of Java's layout managers to account for differences in rendering between different machines, their applications translate to this new environment well. Unfortunately, not all applications have been designed in this way, and it is sometimes felt that the burden of testing under multiple different L&Fs is too difficult. Although you can use the mechanisms described later in this chapter to force your application to use a particular L&F (like the always available Metal), you should avoid taking this step lightly; it takes choices away from your users and definitely reduces the likelihood of the application's acceptance on highly consistent platforms like the Macintosh. If, despite this, you feel such a restriction is necessary, at least provide an easily found configuration option by which the users can choose to overrule you and use their preferred L&F at their own risk, so to speak.

If you do want to work with the Mac L&F, but lack a Mac on which you can test your application's layout, you can download the MacMetrics Metal theme from this book's web site: http://www.oreilly.com/catalog/jswing2/. This theme modifies Metal so that its components closely approximate the dimensions of the Mac L&F. It was graciously shared with us by Lee Ann Rucker who developed it while creating the Mac L&F itself. Figure 26-1 shows an example of how the theme alters a Metal interface. To use it, simply be sure MacMetrics.jar is in your application's classpath, and arrange for the following lines of code to be executed:

  import javax.swing.plaf.metal.MetalLookAndFeel;    . . .    MetalLookAndFeel.setCurrentTheme(new MacMetricsTheme( ));
Figure 26-1. The defulat (left) and MacMetrics Metal themes on a Linux workstation
figs/swng2.2601.gif

If you change the theme after any Swing components have already been created, you also need to call SwingUtilities.updateComponentTreeUI for each top-level container in your application, as discussed in Section 26.3.6.7 later in this chapter.

Testing against the Metal, Motif, MacMetrics, and Windows L&Fs can provide some reassurance that your design is robust and cross-platform.

If you'd like your application to go even further in being a "good Mac citizen," we suggest you read Apple's technical note 2031, "Java Runtime Properties for Mac OS X," available at http://developer.apple.com/technotes/tn/tn2031.html . There, you'll learn how to enable Swing to use the global Macintosh menu bar (through a simple property setting that defaults to off because most Java applications haven't been designed to accommodate this style of interface). The document also discusses ways of taking advantage of hardware graphics acceleration and other Mac-specific features. There is an even more detailed discussion, including some very good advice, in Chapter 5 of Early Adopter Mac OS X Java (Wrox Press).



Java Swing
Graphic Java 2: Mastering the Jfc, By Geary, 3Rd Edition, Volume 2: Swing
ISBN: 0130796670
EAN: 2147483647
Year: 2001
Pages: 289
Authors: David Geary

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net