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

Technologies: Java 5+

This part 4 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 covered JPanel through JSplitPane. And Part 4 here 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.

JTabbedPane

Key Type Value
TabbedPane.ancestorInputMap Input map javax.swing.plaf.InputMapUIResource
TabbedPane.background Color 174, 178, 195
TabbedPane.contentBorderInsets Insets 2, 2, 2, 2
TabbedPane.contentOpaque Boolean true
TabbedPane.darkShadow Color 99, 101, 111
TabbedPane.focus Color 178, 77, 122
TabbedPane.focusInputMap Input map javax.swing.plaf.InputMapUIResource
TabbedPane.font Font Dialog, 12.0
TabbedPane.foreground Color 0, 0, 0
TabbedPane.highlight Color 220, 222, 229
TabbedPane.light Color 220, 222, 229
TabbedPane.selectedTabPadInsets Insets 3, 0, 1, 0
TabbedPane.shadow Color 99, 101, 111
TabbedPane.tabAreaInsets Insets 4, 2, 0, 8
TabbedPane.tabInsets Insets 3, 4, 3, 4
TabbedPane.tabRunOverlay Integer 2
TabbedPane.tabsOpaque Boolean true
TabbedPane.tabsOverlapBorder Boolean false
TabbedPane.textIconGap Integer 4
TabbedPane.unselectedTabBackground Color 147, 151, 165
TabbedPane.unselectedTabForeground Color 0, 0, 0
TabbedPane.unselectedTabHighlight Color 210, 215, 235
TabbedPane.unselectedTabShadow Color 102, 105, 115

JTable

Key Type Value
Table.ancestorInputMap Input map javax.swing.plaf.InputMapUIResource
Table.ancestorInputMap.RightToLeft Input map javax.swing.plaf.InputMapUIResource
Table.ascendingSortIcon Icon sun.swing.icon.SortArrowIcon
Table.background Color 174, 178, 195
Table.descendingSortIcon Icon sun.swing.icon.SortArrowIcon
Table.dropLineColor Color 99, 101, 111
Table.dropLineShortColor Color 178, 77, 122
Table.focusCellBackground Color 174, 178, 195
Table.focusCellForeground Color 0, 0, 0
Table.focusCellHighlightBorder Border javax.swing.plaf.BorderUIResource$LineBorderUIResource
Table.font Font Dialog, 12.0
Table.foreground Color 0, 0, 0
Table.gridColor Color 128, 128, 128
Table.selectionBackground Color 0, 0, 0
Table.selectionForeground Color 255, 247, 233
Table.sortIconColor Color 99, 101, 111
TableHeader.ancestorInputMap Input map javax.swing.plaf.InputMapUIResource
TableHeader.background Color 174, 178, 195
TableHeader.cellBorder Border javax.swing.plaf.BorderUIResource$BevelBorderUIResource
TableHeader.focusCellBackground Color 255, 247, 233
TableHeader.font Font Dialog, 12.0
TableHeader.foreground Color 0, 0, 0

Note: JTable is shown above within a JScrollPane, as it is typically used. The first row is selected, and the first cell focused for editing.

Special features

  • The UIDefaults "Table.ascendingSortIcon" and "Table.descendingSortIcon" contain the icons used in the table header to indicate a sortable column.

    Table.ascendingSortIcon
    17 x 7

    Table.descendingSortIcon
    17 x 7

Problems

  • There is no visual difference between an enabled and disabled JTable (this is common among look and feels).
  • When a cell is selected for editing, a black outline is drawn around the cell instead of the pink outline used for other focused components. The UIDefaults "Table.dropLineShortColor" that contains the pink focus color doesn't appear to be used.

JTextArea

Key Type Value
TextArea.background Color 174, 178, 195
TextArea.border Border javax.swing.plaf.basic.BasicBorders$MarginBorder
TextArea.caretBlinkRate Integer 500
TextArea.caretForeground Color 0, 0, 0
TextArea.focusInputMap Input map javax.swing.plaf.InputMapUIResource
TextArea.font Font Monospaced, 12.0
TextArea.foreground Color 0, 0, 0
TextArea.inactiveForeground Color 128, 128, 128
TextArea.margin Insets 0, 0, 0, 0
TextArea.selectionBackground Color 0, 0, 0
TextArea.selectionForeground Color 255, 247, 233

Note: JTextArea is shown above within a JScrollPane, as it is typically used. The first row is selected.

Problems

  • An editable JTextArea only indicates the keyboard focus by adding a black caret. The component doesn't draw the pink outline used by other components to indicate they've got the focus.
  • Text selections are only visible when the component is enabled and focused (most look and feels act the same).
  • The margins are crowded, but can be changed using setMargin( Insets m ).
  • JTextArea 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 ).

JTextField

Key Type Value
TextField.background Color 174, 178, 195
TextField.border Border javax.swing.plaf.BorderUIResource$CompoundBorderUIResource
TextField.caretBlinkRate Integer 500
TextField.caretForeground Color 0, 0, 0
TextField.darkShadow Color 0, 0, 0
TextField.focusInputMap Input map javax.swing.plaf.InputMapUIResource
TextField.font Font SansSerif, 12.0
TextField.foreground Color 0, 0, 0
TextField.highlight Color 220, 222, 229
TextField.inactiveBackground Color 174, 178, 195
TextField.inactiveForeground Color 128, 128, 128
TextField.light Color 220, 222, 229
TextField.margin Insets 0, 0, 0, 0
TextField.selectionBackground Color 0, 0, 0
TextField.selectionForeground Color 255, 247, 233
TextField.shadow Color 99, 101, 111

Note: JTextField is shown above with the first four characters selected.

Special features

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

    TextField.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 ).

JTextPane

Key Type Value
TextPane.background Color 255, 255, 255
TextPane.border Border javax.swing.plaf.basic.BasicBorders$MarginBorder
TextPane.caretBlinkRate Integer 500
TextPane.caretForeground Color 0, 0, 0
TextPane.focusInputMap Input map javax.swing.plaf.InputMapUIResource
TextPane.font Font Serif, 12.0
TextPane.foreground Color 0, 0, 0
TextPane.inactiveForeground Color 128, 128, 128
TextPane.margin Insets 3, 3, 3, 3
TextPane.selectionBackground Color 192, 192, 192
TextPane.selectionForeground Color 255, 247, 233

Note: JTextPane is shown within a JScrollPane, as it is typically used. The first row is selected.

Problems

  • An editable JTextPane only indicates the keyboard focus by adding a black caret. The component doesn't draw the pink outline used by other components to indicate they have the focus.
  • Text selections are only visible when the component is enabled and focused (most look and feels act the same).
  • The margins are crowded, but can be changed using setMargin( Insets m ).
  • JTextPane and JEditorPane both default to the generic "Serif" font, but all 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 ).
  • Selected text colors have poor contrast (white on light gray) and they differ from those used by other text components (black on white instead of black on gray) (other look and feels use consistent colors across all text components). You can change the component's colors using setForeground( Color c ), setBackground( Color c ), setSelectionColor( Color c ), and setSelectedTextColor( Color c ).

JToggleButton

Key Type Value
ToggleButton.background Color 174, 178, 195
ToggleButton.border Border javax.swing.plaf.BorderUIResource$CompoundBorderUIResource
ToggleButton.darkShadow Color 0, 0, 0
ToggleButton.focus Color 0, 0, 0
ToggleButton.focusInputMap Input map javax.swing.plaf.InputMapUIResource
ToggleButton.font Font Dialog, 12.0
ToggleButton.foreground Color 0, 0, 0
ToggleButton.highlight Color 220, 222, 229
ToggleButton.light Color 220, 222, 229
ToggleButton.margin Insets 2, 14, 2, 14
ToggleButton.select Color 147, 151, 165
ToggleButton.shadow Color 99, 101, 111
ToggleButton.textIconGap Integer 4
ToggleButton.textShiftOffset Integer 0

Special features

  • The UIDefaults "ToggleButton.border" contains a border object that draws the beveled border and pink keyboard focus outline around the toggle button.

    ToggleButton.border

Problems

  • Unlike a JButton, an unselected JToggleButton has a transparent background.
  • The UIDefaults "ToggleButton.focus" black color is ignored and the keyboard focus outline drawn in pink instead. However, there is no UIDefaults entry for the pink color, though it can be found on other components, such as "CheckBox.focus" or "RadioButton.focus".
  • JToggleButton uses different larger margins than a JButton. You can change margins using setMargin( Insets m ).

JToolBar

Key Type Value
ToolBar.ancestorInputMap Input map javax.swing.plaf.InputMapUIResource
ToolBar.background Color 174, 178, 195
ToolBar.border Border javax.swing.plaf.BorderUIResource$EtchedBorderUIResource
ToolBar.darkShadow Color 0, 0, 0
ToolBar.dockingBackground Color 174, 178, 195
ToolBar.dockingForeground Color 255, 0, 0
ToolBar.floatingBackground Color 174, 178, 195
ToolBar.floatingForeground Color 64, 64, 64
ToolBar.font Font Dialog, 12.0
ToolBar.foreground Color 0, 0, 0
ToolBar.highlight Color 220, 222, 229
ToolBar.light Color 220, 222, 229
ToolBar.separatorSize Dimension 10, 10
ToolBar.shadow Color 99, 101, 111

Note: JToolBar is shown with two buttons divided by a JToolBar.Separator.

Special features

  • The UIDefaults "ToolBar.border" contains a border object that draws the etched border around the tool bar.

    ToolBar.border

Problems

  • When the tool bar is floatable, there is no tear-off handle (other look and feels draw a handle at the left side of the tool bar). Without a handle to grab, the tool bar cannot be torn off to float.
  • When the tool bar's rollover mode is enabled, the borders of all buttons on the tool bar are disabled (some look and feels do this, and some do not).
  • A JToolBar.Separator is drawn as an empty gap (some look and feels draw a vertical line for tool bar separators).
  • There is no visual difference between an enabled and disabled JToolBar (most look and feels act the same).
  • The tool bar has no margins. These can be set with setMargin( Insets m ).

JToolTip

Key Type Value
ToolTip.background Color 255, 247, 233
ToolTip.border Border com.sun.java.swing.plaf.motif.MotifBorders$BevelBorder
ToolTip.font Font SansSerif, 12.0
ToolTip.foreground Color 0, 0, 0
ToolTipManager.enableToolTipMode String "allWindows"

Special features

  • The UIDefaults "ToolTip.border" contains a border object that draws the beveled border around the tool tip.

    ToolTip.border

Problems

  • There is no visual difference between an enabled and disabled JToolTip (most look and feels act the same). Of course, a disabled tool tip doesn't make much sense anyway.

JTree

Key Type Value
Tree.ancestorInputMap Input map javax.swing.plaf.InputMapUIResource
Tree.background Color 147, 151, 165
Tree.changeSelectionWithFocus Boolean true
Tree.closedIcon Icon sun.swing.ImageIconUIResource
Tree.collapsedIcon Icon com.sun.java.swing.plaf.motif.MotifTreeUI$MotifCollapsedIcon
Tree.drawsFocusBorderAroundIcon Boolean true
Tree.dropLineColor Color 99, 101, 111
Tree.editorBorder Border com.sun.java.swing.plaf.motif.MotifBorders$FocusBorder
Tree.editorBorderSelectionColor Color 178, 77, 122
Tree.expandedIcon Icon com.sun.java.swing.plaf.motif.MotifTreeUI$MotifExpandedIcon
Tree.focusInputMap Input map javax.swing.plaf.InputMapUIResource
Tree.focusInputMap.RightToLeft Input map javax.swing.plaf.InputMapUIResource
Tree.font Font Dialog, 12.0
Tree.foreground Color 0, 0, 0
Tree.hash Color 0, 0, 0
Tree.iconBackground Color 174, 178, 195
Tree.iconForeground Color 99, 101, 111
Tree.iconHighlight Color 220, 222, 229
Tree.iconShadow Color 99, 101, 111
Tree.leafIcon Icon javax.swing.plaf.IconUIResource
Tree.leftChildIndent Integer 7
Tree.lineTypeDashed Boolean false
Tree.openIcon Icon sun.swing.ImageIconUIResource
Tree.paintLines Boolean true
Tree.rightChildIndent Integer 13
Tree.rowHeight Integer 18
Tree.scrollsOnExpand Boolean true
Tree.selectionBackground Color 255, 247, 233
Tree.selectionBorderColor Color 178, 77, 122
Tree.selectionForeground Color 0, 0, 0
Tree.textBackground Color 147, 151, 165
Tree.textForeground Color 0, 0, 0
Tree.timeFactor Long 1000

Note: JTree is shown within a JScrollPane, as it is typically used. The first child is selected.

Special features

  • The UIDefaults "Tree.closedIcon", "Tree.collapsedIcon", "Tree.expandedIcon", "Tree.leafIcon", and "Tree.openIcon" contain the default icons for tree nodes. Unfortunately, they're ugly.

    Tree.closedIcon
    17 x 13

    Tree.collapsedIcon
    14 x 14

    Tree.expandedIcon
    14 x 14

    Tree.leafIcon
    13 x 13

    Tree.openIcon
    17 x 13
     
  • The UIDefaults "Tree.editorBorder" contains a border object that draws an outline border for an editable tree node.

    Tree.editorBorder

Problems

  • The JTree background is a dark gray while the background for every other component is a light gray.
  • A selected JTree node is shown with black text on a beige background, while most other components show selections with white text on a black background (such as a JList or a JTable).
  • A JTree has no margins, which leaves the tree nodes looking crowded. This can be fixed by overriding the tree cell renderer and adding margins in the rendered component. The renderer is set with setCellRenderer( TreeCellRenderer r ).
  • When a JTree is disabled, the open and close icons are dimmed, but the rest are not (most look and feels dim all of the icons). The lines connecting tree nodes are also left unchanged (most look and feels don't draw these lines at all).

JViewport

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

Additional UIDefaults for the CDE/Motif look and feel

The look and feel UIDefaults include a few additional entries not associated with any single component.

AuditoryCues

Key Type Value
AuditoryCues.allAuditoryCues Array java.lang.Object
AuditoryCues.cueList Array java.lang.Object
AuditoryCues.noAuditoryCues Array java.lang.Object

html

Key Type Value
html.missingImage Icon sun.swing.ImageIconUIResource
html.pendingImage Icon sun.swing.ImageIconUIResource

Special features

  • The UIDefaults "html.missingImage" and "html.pendingImage" are used when loading HTML documents and their images.

    html.missingImage
    38 x 38

    html.pendingImage
    38 x 38

System

Key Type Value
activeCaption Color 0, 0, 128
activeCaptionBorder Color 178, 77, 122
activeCaptionText Color 255, 255, 255
control Color 174, 178, 195
controlDkShadow Color 0, 0, 0
controlHighlight Color 220, 222, 229
controlLightShadow Color 147, 151, 165
controlLtHighlight Color 220, 222, 229
controlShadow Color 99, 101, 111
controlText Color 0, 0, 0
desktop Color 0, 92, 92
inactiveCaption Color 174, 178, 195
inactiveCaptionBorder Color 174, 178, 195
inactiveCaptionText Color 0, 0, 0
info Color 255, 247, 233
infoText Color 0, 0, 0
menu Color 174, 178, 195
menuText Color 0, 0, 0
scrollbar Color 174, 178, 195
text Color 255, 247, 233
textHighlight Color 0, 0, 0
textHighlightText Color 255, 247, 233
textInactiveText Color 128, 128, 128
textText Color 0, 0, 0
window Color 174, 178, 195
windowBorder Color 174, 178, 195
windowText Color 0, 0, 0

Special features

  • The above colors mimic the names of well-defined colors in the SystemColor class. However, the SystemColors loosely track OS theme colors, while the UIDefaults colors here track the look and feel.

TitledBorder

Key Type Value
TitledBorder.border Border javax.swing.plaf.BorderUIResource$EtchedBorderUIResource
TitledBorder.font Font Dialog, 12.0
TitledBorder.titleColor Color 0, 0, 0

Special features

  • The UIDefaults "TitledBorder.border" contains a border object that draws the default etched border of a TitledBorder.

    TitledBorder.border

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