Java tip: Problems and special features of the CDE/Motif look and feel, part 3

Technologies: Java 5+

This part 3 of 4 articles continues a component by component review of problems, workarounds, and special features for the classic Java Swing CDE/Motif look and feel. Example images are included along with UIDefaults values, color swatches, and icon images.

Part 1 of this series reviewed how to select the look and feel and access its UIDefaults, then started an alphabetical run through its components from JButton through JEditorPane. Part 2 covered JFileChooser through JOptionPane. Part 3 here covers JPanel through JSplitPane. And Part 4 covers JTabbedPane through JViewport.

Working with the CDE/Motif look and feel

Below continues an alphabetical run through the look and feel's UIDefaults and Swing components. Non-string keys and UI class values are implementation artifacts and are not included here.

JPanel

Key Type Value
Panel.background Color 174, 178, 195
Panel.font Font Dialog, 12.0
Panel.foreground Color 0, 0, 0

JPasswordField

Key Type Value
PasswordField.background Color 174, 178, 195
PasswordField.border Border javax.swing.plaf.BorderUIResource$CompoundBorderUIResource
PasswordField.caretBlinkRate Integer 500
PasswordField.caretForeground Color 0, 0, 0
PasswordField.echoChar Character '*'
PasswordField.focusInputMap Input map javax.swing.plaf.InputMapUIResource
PasswordField.font Font Monospaced, 12.0
PasswordField.foreground Color 0, 0, 0
PasswordField.inactiveBackground Color 174, 178, 195
PasswordField.inactiveForeground Color 128, 128, 128
PasswordField.margin Insets 0, 0, 0, 0
PasswordField.selectionBackground Color 0, 0, 0
PasswordField.selectionForeground Color 255, 247, 233

Note: JPasswordField is shown with the first four characters selected.

Special features

  • The UIDefaults "PasswordField.border" contains a border object that draws the recessed beveled border around the text field.

    PasswordField.border

Problems

  • There is no UIDefaults color for the pink outline indicating the keyboard focus. The color can be found on other components, such as "CheckBox.focus" or "RadioButton.focus".
  • The field's text is crowded against the edges of the component border. You can change the margins with setMargin( Insets m ).

JPopupMenu

Key Type Value
PopupMenu.background Color 174, 178, 195
PopupMenu.border Border javax.swing.plaf.BorderUIResource$CompoundBorderUIResource
PopupMenu.consumeEventOnClose Boolean true
PopupMenu.font Font Dialog, 12.0
PopupMenu.foreground Color 0, 0, 0
PopupMenu.selectedWindowInputMapBindings Array java.lang.Object
PopupMenu.selectedWindowInputMapBindings.RightToLeft Array java.lang.Object

Special features

  • The menu label set on the constructor or with setLabel( String s ) is used to title the menu (most look and feels ignore the popup menu label and present menus without titles).

Problems

  • There is no visual difference between an enabled and disabled JPopupMenu (most look and feels act the same, but a few alter the menu's appearance when disabled).

JPopupMenu.Separator

Problems

  • There are no UIDefaults for the appearance of a JPopupMenu.Separator.
  • There is no visual difference between an enabled and disabled JPopupMenu.Separator (some look and feels dim or hide a disabled separator).

JProgressBar

Key Type Value
ProgressBar.background Color 174, 178, 195
ProgressBar.border Border com.sun.java.swing.plaf.motif.MotifBorders$BevelBorder
ProgressBar.cellLength Integer 6
ProgressBar.cellSpacing Integer 0
ProgressBar.cycleTime Integer 3000
ProgressBar.font Font Dialog, 12.0
ProgressBar.foreground Color 147, 151, 165
ProgressBar.horizontalSize Dimension 146, 12
ProgressBar.repaintInterval Integer 50
ProgressBar.selectionBackground Color 0, 0, 0
ProgressBar.selectionForeground Color 174, 178, 195
ProgressBar.verticalSize Dimension 12, 146

Special features

  • The UIDefaults "ProgressBar.border" contains a border object that draws the recessed beveled border around the progress bar.

    ProgressBar.border

Problems

  • There is no visual difference between an enabled and disabled JProgressBar (some look and feels use dimmed colors for a disabled progress bar).
  • The progress bar's height changes depending upon the presence of a progress string (most look and feels use the same height with or without a progress string). This will cause layout changes if the string is added or removed during use.

JRadioButton

Key Type Value
RadioButton.background Color 174, 178, 195
RadioButton.border Border javax.swing.plaf.BorderUIResource$CompoundBorderUIResource
RadioButton.darkShadow Color 0, 0, 0
RadioButton.focus Color 178, 77, 122
RadioButton.focusInputMap Input map javax.swing.plaf.InputMapUIResource
RadioButton.font Font Dialog, 12.0
RadioButton.foreground Color 0, 0, 0
RadioButton.highlight Color 220, 222, 229
RadioButton.icon Icon com.sun.java.swing.plaf.motif.MotifIconFactory$RadioButtonIcon
RadioButton.light Color 220, 222, 229
RadioButton.margin Insets 4, 2, 4, 2
RadioButton.shadow Color 99, 101, 111
RadioButton.textIconGap Integer 8
RadioButton.textShiftOffset Integer 0

Special features

  • The UIDefaults "RadioButton.border" contains a border object that draws the pink keyboard focus outline and a beveled border, even though a radio button doesn't have a beveled border. While the border can be used to create button-like extensions to AbstractButton, the border class in "Button.border" is probably a better choice.

    RadioButton.border
  • The UIDefaults "RadioButton.icon" contains the unselected button outline.

    RadioButton.icon
    14 x 14

Problems

  • There is no UIDefaults icon for the selected button (this is typical for all look and feels). If you need this icon, create a JRadioButton component and paint it into the Graphics context of a BufferedImage. Then create an ImageIcon using that BufferedImage.
  • There is no UIDefaults for the color of the pink dot at the center of the radio button, but "RadioButton.focus" can be used instead.
  • When a JRadioButton is disabled, its label is dimmed but not the radio button. So, if you don't include a label on a radio button (such as for a table column of radio buttons) the user can't tell if the component is disabled (other look and feels don't have this problem because they dim the radio button too). If you need to show the disabled state on the radio button, you can use your own icons to override the radio button icon.
  • When a JRadioButton has the keyboard focus, it draws a pink outline around the entire component, including the label. When there's no label, this can look odd (other look and feels outline the radio button itself, instead of the entire component).
  • A JRadioButton draws an opaque background by default (some look and feels do and some don't). If you're using a colored parent container and need it to show through the component, you can disable the JRadioButton background with setOpaque( boolean b ).

JRadioButtonMenuItem

Key Type Value
RadioButtonMenuItem.acceleratorFont Font Dialog, 12.0
RadioButtonMenuItem.acceleratorForeground Color 0, 0, 0
RadioButtonMenuItem.acceleratorSelectionForeground Color 0, 0, 0
RadioButtonMenuItem.arrowIcon Icon com.sun.java.swing.plaf.motif.MotifIconFactory$MenuItemArrowIcon
RadioButtonMenuItem.background Color 174, 178, 195
RadioButtonMenuItem.border Border javax.swing.plaf.BorderUIResource$CompoundBorderUIResource
RadioButtonMenuItem.borderPainted Boolean false
RadioButtonMenuItem.checkIcon Icon com.sun.java.swing.plaf.motif.MotifIconFactory$RadioButtonIcon
RadioButtonMenuItem.font Font Dialog, 12.0
RadioButtonMenuItem.foreground Color 0, 0, 0
RadioButtonMenuItem.margin Insets 2, 2, 2, 2
RadioButtonMenuItem.selectionBackground Color 165, 165, 165
RadioButtonMenuItem.selectionForeground Color 0, 0, 0

Special features

  • The UIDefaults "RadioButtonMenuItem.border" contains a border object that draws the recessed border around an armed menu item.

    RadioButtonMenuItem.border
  • The UIDefaults "RadioButtonMenuItem.checkIcon" contains the unselected radio button.

    RadioButtonMenuItem.checkIcon
    14 x 14

Problems

  • The UIDefaults "RadioButtonMenuItem.arrowIcon" is empty, but it isn't needed anyway (the icon is an implementation artifact that comes from using a common base class for all menu item implementations).
  • There is no UIDefaults icon for the selected radio button (this is typical for all look and feels).
  • There is no UIDefaults for the color of the pink dot at the center of the radio button, but "RadioButton.focus" can be used instead.
  • Unlike a JRadioButton, setting the icon on a JRadioButtonMenuItem adds the icon beside the radio button instead of replacing the button icon (this is typical for all look and feels). There is no simple way to replace the radio button icon itself.
  • If any menu item on a menu has an icon, all of the menu items leave room for the icon (most look and feels do this). This can look odd if a menu item has an icon but no label. To avoid this look, always give menu items labels.

JRootPane

Key Type Value
RootPane.ancestorInputMap Input map javax.swing.plaf.InputMapUIResource
RootPane.defaultButtonWindowKeyBindings Array java.lang.Object

JScrollBar

Key Type Value
ScrollBar.allowsAbsolutePositioning Boolean true
ScrollBar.ancestorInputMap Input map javax.swing.plaf.InputMapUIResource
ScrollBar.ancestorInputMap.RightToLeft Input map javax.swing.plaf.InputMapUIResource
ScrollBar.background Color 147, 151, 165
ScrollBar.border Border com.sun.java.swing.plaf.motif.MotifBorders$BevelBorder
ScrollBar.foreground Color 174, 178, 195
ScrollBar.maximumThumbSize Dimension 4096, 4096
ScrollBar.minimumThumbSize Dimension 8, 8
ScrollBar.thumb Color 174, 178, 195
ScrollBar.thumbDarkShadow Color 0, 0, 0
ScrollBar.thumbHighlight Color 220, 222, 229
ScrollBar.thumbShadow Color 99, 101, 111
ScrollBar.track Color 147, 151, 165
ScrollBar.trackHighlight Color 0, 0, 0
ScrollBar.width Integer 16

Special features

  • The UIDefaults "ScrollBar.border" contains a border object that draws the recessed beveled border around the scroll bar.

    ScrollBar.border

Problems

  • A disabled scroll bar hides the thumb instead of just disabling the thumb's movement. This makes it impossible for the user to see the thumb's current setting when disabled (the Metal and Nimbus look and feels do the same thing, but Mac, Windows, and Linux native look and feels always show the thumb, but disable its movement).
  • The component does not show the keyboard focus. Other components draw a pink outline around the component when they've got the focus.

JScrollPane

Key Type Value
ScrollPane.ancestorInputMap Input map javax.swing.plaf.InputMapUIResource
ScrollPane.ancestorInputMap.RightToLeft Input map javax.swing.plaf.InputMapUIResource
ScrollPane.background Color 174, 178, 195
ScrollPane.font Font Dialog, 12.0
ScrollPane.foreground Color 0, 0, 0
ScrollPane.viewportBorder Border com.sun.java.swing.plaf.motif.MotifBorders$BevelBorder

Special features

  • The UIDefaults "ScrollPane.viewportBorder" contains a border object that draws the recessed beveled border around the scroll pane viewport.

    ScrollPane.viewportBorder

Problems

  • There is no visual difference between an enabled and disabled JScrollPane (most look and feels act the same way).

JSeparator

Key Type Value
Separator.background Color 220, 222, 229
Separator.foreground Color 99, 101, 111
Separator.highlight Color 220, 222, 229
Separator.shadow Color 99, 101, 111

Problems

  • There is no visual difference between an enabled and disabled JSeparator (most look and feels act the same way, though a few will dim a disabled separator).

JSlider

Key Type Value
Slider.background Color 147, 151, 165
Slider.border Border javax.swing.plaf.BorderUIResource$CompoundBorderUIResource
Slider.focus Color 0, 0, 0
Slider.focusInputMap Input map javax.swing.plaf.InputMapUIResource
Slider.focusInputMap.RightToLeft Input map javax.swing.plaf.InputMapUIResource
Slider.focusInsets Insets 0, 0, 0, 0
Slider.font Font Dialog, 12.0
Slider.foreground Color 174, 178, 195
Slider.highlight Color 220, 222, 229
Slider.horizontalSize Dimension 200, 21
Slider.minimumHorizontalSize Dimension 36, 21
Slider.minimumVerticalSize Dimension 21, 36
Slider.shadow Color 99, 101, 111
Slider.tickColor Color 0, 0, 0
Slider.verticalSize Dimension 21, 200

Special features

  • The UIDefaults "Slider.border" contains a border object that draws the recessed beveled border and pink keyboard focus outline around the slider.

    Slider.border

Problems

  • The slider has no track (other look and feels do). Instead the slider and its ticks and labels are all enclosed within a recessed background rectangle. Because there is no track, calling setPaintTrack( false ) has no effect. To remove the background rectangle, call setOpaque( false ) to disable the dark gray background, and setBorder( null ) to remove the beveled border. However, removing the border also removes the pink outline when the component has the keyboard focus.
  • The black keyboard focus color in the UIDefaults "Slider.focus" is ignored. The drawn focus outline is pink instead, like that on most other focusable components. The pink color can be found on other components, such as "CheckBox.focus" or "RadioButton.focus".

JSpinner

Key Type Value
Spinner.ancestorInputMap Input map javax.swing.plaf.InputMapUIResource
Spinner.arrowButtonSize Dimension 16, 5
Spinner.background Color 174, 178, 195
Spinner.border Border javax.swing.plaf.BorderUIResource$CompoundBorderUIResource
Spinner.editorAlignment Integer 11
Spinner.editorBorderPainted Boolean false
Spinner.font Font Monospaced, 12.0
Spinner.foreground Color 174, 178, 195

Special features

  • The UIDefaults "Spinner.border" contains a border object that draws the recessed beveled border around the spinner.

    Spinner.border

Problems

  • The spinner's margins are very narrow, creating a crowded look. The margins can be changed with setMargin( Insets m ).
  • JSpinner defaults to the generic "Monospaced" font, but most other text components default to "SansSerif". And all labels, button text, menu items, etc., default to the "Dialog" font, which is also sans-serif. You can override this inconsistency with setFont( Font f ).
  • There is no UIDefaults color for the pink outline indicating the keyboard focus. The color can be found on other components, such as "CheckBox.focus" or "RadioButton.focus".

JSplitPane

Key Type Value
SplitPane.activeThumb Color 178, 77, 122
SplitPane.ancestorInputMap Input map javax.swing.plaf.InputMapUIResource
SplitPane.background Color 174, 178, 195
SplitPane.border Border javax.swing.plaf.basic.BasicBorders$SplitPaneBorder
SplitPane.darkShadow Color 0, 0, 0
SplitPane.dividerSize Integer 20
SplitPane.highlight Color 220, 222, 229
SplitPane.shadow Color 99, 101, 111
SplitPaneDivider.border Border javax.swing.plaf.basic.BasicBorders$SplitPaneDividerBorder
SplitPaneDivider.draggingColor Color 64, 64, 64

Problems

  • The divider looks like a conventional slider, but the thumb doesn't move along the slider-like track. Instead it drags orthogonal to the track to adjust the split. This will confuse some users.
  • The divider is thick. While setDividerSize( int s ) can be used to reduce the size, it won't shrink any smaller than 14 pixels wide (which is still thick compared to other look and feels).
  • The UIDefaults "SplitPane.activeThumb" color is never used. When using a continuous layout, enabled with setContinuousLayout( true ), the divider drags without changing its appearance. When using a non-continuous layout, the divider drags as a thick black line.

Downloads

The CDE/Motif UIDefaults colors are available for download in the X11 rgb.txt file format:

Further reading

Related articles at NadeauSoftware.com

Web articles

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Nadeau software consulting
Nadeau software consulting