up previous next contents
Up: java-on-mac Previous: Slightly different menus for Next: A note on using   Contents

A potpourri of other items

In this section I'm going to briefly cover a number of other tweaks you may have to make so your Java/Swing application will function more like a native Mac OS X application.

File choosers

This Apple link recommends that you use the java.awt.FileDialog instead of the javax.swing.JFileChooser, as it looks more like the native file chooser. See that URL for screenshots comparing the two views.

Horizontal and vertical scrolling

That same link also suggests that for windows that use scrollbars, Java applications should set code for the scrollpanes as follows:


This sets the scrollpane to always show the horizontal and vertical scrollbars, even if scrolling is not required.

In previous figures you've seen my application without this scrollbar setting, so now I'll show two figures withe scrollbar setting. Figure 10.1 shows what the editing area looks like with this new setting, but without the need for scrollbars. You can see the extra area reserved on the bottom and right sides of the editing area.

Figure 10.1: The scrollbar areas are reserved, but scrolling is not needed.
Image 8-with-scrollbars

Figure 10.2 shows what the editing area looks like when both horizontal and vertical scrolling is needed. As you can see from the two figures, because the areas are already reserved, my text editing area won't jump around when scrolling is required.

Figure 10.2: This shows the editing area after the SCROLLBAR_ALWAYS settings are added.
Image 9-with-scrolling

Making this change offers two advantages. First, it conforms to the Mac OS X look and feel. Second, it keeps you content from jumping around when scrollbars are needed. That is, if you don't set these two lines of code, and then something happens where the scrollbars are suddenly needed in the application, they will be shown, and content in the scrollpane may jump around at that moment, as the displayable portion of the window suddenly decreases. Adding these two lines of code keeps that "jumpiness" from occurring.

Tab sizes

I've read that you may also want/need control over your tab sizes, but I haven't seen this on my system. I'm writing and testing this on a MacBook Pro running Mac OS X 10.4.10, with a JVM version of 1.5.0_07.

If, however, you see that your your Java/Swing application has larger tabs than a Mac application (like the Get Info dialog in iTunes) you can try setting the following system parameter. On my system it had no noticeable impact:

System.setProperty("com.apple.macos.smallTabs", "true");