3D PLM Enterprise Architecture

Webtop

Customizing Swing Components in the Portal

How to extend swing components and use the Portal look&feel colors
Technical Article

The "Portal Look and Feel" is being developed in order to implement the ergonomic displays. If you want to create your own swing components, pay attention to the choice of colors. You should better use the current "Look & Feel" colors instead of setting them statically in your code.

If you overwrite a Swing Component call the subclass in order to get the right colors.
If you create your own component, you can call the UIManager class in order to get each color defined by the current Look & Feel. For example UIManager.getColor("Tree.background") returns the default color of the JTree background.

Samples: Implementation of a TreeCellRenderer

1 - If you override a Swing component:
In order to set the right color, you have to request them to the subclass.

Sample: Overwrite the DefaultTreeCellRenderer.

public class MyDefaultTreeCellRenderer extends DefaultTreeCellRenderer
{
  public MyDefaultTreeCellRenderer()
  {
    super();
  }
  public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                                                boolean leaf, int row, boolean hasFocus)
  {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

    if (value instanceof TreeNodeWithIcon)
        setIcon(((TreeNodeWithIcon)value).getIcon());

    return this;
  }
}

2 - If you create your own component:

The Look and Feel defines a group of colors for each Swing component and stores them in the UIManager class. If you want to create your own component with the selected L&F colors, you have to request them to the UIManager class.

Sample: Create your on TreeCellRenderer with a JLabel.

public class MyTreeCellRenderer extends JLabel
                implements TreeCellRenderer
{
  public ZyTreeCellRenderer()
  {
    super();
  }
  public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,       
                                                boolean leaf, int row, boolean hasFocus)
  {
    setText(value.toString());
    if (sel)
    {
      setForeground(UIManager.getColor("Tree.selectionForeground"));
      setBackground(UIManager.getColor("Tree.selectionBackground"));
    }
    else
    {
      setForeground(UIManager.getColor("Tree.textForeground"));
      setBackground(UIManager.getColor("Tree.textBackground"));
    }
    if (value instanceof TreeNodeWithIcon)
       setIcon(((TreeNodeWithIcon)value).getIcon());
    return this;
  }
}

A list of key words defined for UIManager:

"Button.font",
"Button.background",
"Button.foreground",
"Button.border",
"Button.margin",
"Button.textIconGap",
"Button.textShiftOffset",
"Button.disabledText",
"Button.select",
"Button.focus",

"ToggleButton.font",
"ToggleButton.background",
"ToggleButton.foreground",
"ToggleButton.border",
"ToggleButton.margin",
"ToggleButton.textIconGap",
"ToggleButton.textShiftOffset",
"ToggleButton.select",
"ToggleButton.text",
"ToggleButton.disabledText",
"ToggleButton.disabledSelectedText",
"ToggleButton.disabledBackground",
"ToggleButton.disabledSelectedBackground",
"ToggleButton.focus",

"RadioButton.font",
"RadioButton.background",
"RadioButton.foreground",
"RadioButton.border",
"RadioButton.margin",
"RadioButton.textIconGap",
"RadioButton.textShiftOffset",
"RadioButton.icon",
"RadioButton.select",
"RadioButton.focus",

"CheckBox.font",
"CheckBox.background",
"CheckBox.foreground",
"CheckBox.border",
"CheckBox.margin",
"CheckBox.textIconGap",
"CheckBox.textShiftOffset",
"CheckBox.icon"
"CheckBox.disabledText",
"Checkbox.select",
"CheckBox.focus",

"ColorChooser.font",
"ColorChooser.background",
"ColorChooser.foreground",
"ColorChooser.swatchesSwatchSize",
"ColorChooser.swatchesRecentSwatchSize",
"ColorChooser.swatchesDefaultRecentColor",
"ColorChooser.rgbRedMnemonic",
"ColorChooser.rgbGreenMnemonic",
"ColorChooser.rgbBlueMnemonic",

"ComboBox.font",
"ComboBox.background",
"ComboBox.foreground",
"ComboBox.selectionBackground",
"ComboBox.selectionForeground",
"ComboBox.disabledBackground",
"ComboBox.disabledForeground",

"FileChooser.cancelButtonMnemonic",
"FileChooser.saveButtonMnemonic",
"FileChooser.openButtonMnemonic",
"FileChooser.updateButtonMnemonic",
"FileChooser.helpButtonMnemonic",
"FileChooser.newFolderIcon",
"FileChooser.upFolderIcon",
"FileChooser.homeFolderIcon",
"FileChooser.detailsViewIcon",
"FileChooser.listViewIcon",

"FileView.directoryIcon",
"FileView.fileIcon",
"FileView.computerIcon",
"FileView.hardDriveIcon",
"FileView.floppyDriveIcon",

"InternalFrame.titleFont",
"InternalFrame.border",
"InternalFrame.icon",
"InternalFrame.maximizeIcon",
"InternalFrame.minimizeIcon",
"InternalFrame.iconifyIcon",
"InternalFrame.closeIcon",
"InternalFrame.activeTitleBackground",
"InternalFrame.activeTitleForeground",
"InternalFrame.inactiveTitleBackground",
"InternalFrame.inactiveTitleForeground",

"DesktopIcon.border",
"Desktop.background",

"Label.font",
"Label.background",
"Label.foreground",
"Label.disabledForeground",
"Label.disabledShadow",
"Label.border",

"List.font",
"List.background",
"List.foreground",
"List.selectionBackground",
"List.selectionForeground",
"List.focusCellHighlightBorder",
"List.border",
"List.cellRenderer",

"MenuBar.font",
"MenuBar.background",
"MenuBar.foreground",
"MenuBar.border",

"MenuItem.font",
"MenuItem.acceleratorFont",
"MenuItem.background",
"MenuItem.foreground",
"MenuItem.selectionForeground",
"MenuItem.selectionBackground",
"MenuItem.disabledForeground",
"MenuItem.acceleratorForeground",
"MenuItem.acceleratorSelectionForeground",
"MenuItem.border",
"MenuItem.borderPainted",
"MenuItem.margin",
"MenuItem.checkIcon",
"MenuItem.arrowIcon",

"RadioButtonMenuItem.font",
"RadioButtonMenuItem.acceleratorFont",
"RadioButtonMenuItem.background",
"RadioButtonMenuItem.foreground",
"RadioButtonMenuItem.selectionForeground",
"RadioButtonMenuItem.selectionBackground",
"RadioButtonMenuItem.disabledForeground",
"RadioButtonMenuItem.acceleratorForeground",
"RadioButtonMenuItem.acceleratorSelectionForeground",
"RadioButtonMenuItem.border",
"RadioButtonMenuItem.borderPainted",
"RadioButtonMenuItem.margin",
"RadioButtonMenuItem.checkIcon",
"RadioButtonMenuItem.arrowIcon",

"CheckBoxMenuItem.font",
"CheckBoxMenuItem.acceleratorFont",
"CheckBoxMenuItem.background",
"CheckBoxMenuItem.foreground",
"CheckBoxMenuItem.selectionForeground",
"CheckBoxMenuItem.selectionBackground",
"CheckBoxMenuItem.disabledForeground",
"CheckBoxMenuItem.acceleratorForeground",
"CheckBoxMenuItem.acceleratorSelectionForeground",
"CheckBoxMenuItem.border",
"CheckBoxMenuItem.borderPainted",
"CheckBoxMenuItem.margin",
"CheckBoxMenuItem.checkIcon",
"CheckBoxMenuItem.arrowIcon",

"Menu.font",
"Menu.acceleratorFont",
"Menu.background",
"Menu.foreground",
"Menu.selectionForeground",
"Menu.selectionBackground",
"Menu.disabledForeground",
"Menu.acceleratorForeground",
"Menu.acceleratorSelectionForeground",
"Menu.border",
"Menu.borderPainted",
"Menu.margin",
"Menu.checkIcon",
"Menu.arrowIcon",
"Menu.consumesTabs",

"PopupMenu.font",
"PopupMenu.background",
"PopupMenu.foreground",
"PopupMenu.border",

"OptionPane.font",
"OptionPane.background",
"OptionPane.foreground",
"OptionPane.messageForeground",
"OptionPane.border",
"OptionPane.messageAreaBorder",
"OptionPane.buttonAreaBorder",
"OptionPane.minimumSize",
"OptionPane.errorIcon",
"OptionPane.informationIcon",
"OptionPane.warningIcon",
"OptionPane.questionIcon",

"Panel.font",
"Panel.background",
"Panel.foreground",

"ProgressBar.font",
"ProgressBar.foreground",
"ProgressBar.background",
"ProgressBar.selectionForeground",
"ProgressBar.selectionBackground",
"ProgressBar.border",
"ProgressBar.cellLength",
"ProgressBar.cellSpacing",

"Separator.shadow",
"Separator.highlight",

"ScrollBar.background",
"ScrollBar.foreground",
"ScrollBar.track",
"ScrollBar.trackHighlight",
"ScrollBar.thumb",
"ScrollBar.thumbHighlight",
"ScrollBar.thumbDarkShadow",
"ScrollBar.thumbLightShadow",
"ScrollBar.border",
"ScrollBar.minimumThumbSize",
"ScrollBar.maximumThumbSize",

"ScrollPane.font",
"ScrollPane.background",
"ScrollPane.foreground",
"ScrollPane.border",
"ScrollPane.viewportBorder",

"Viewport.font",
"Viewport.background",
"Viewport.foreground",

"Slider.foreground",
"Slider.background",
"Slider.highlight",
"Slider.shadow",
"Slider.focus",
"Slider.border",
"Slider.focusInsets",

"SplitPane.background",
"SplitPane.highlight",
"SplitPane.shadow",
"SplitPane.border",
"SplitPane.dividerSize",

"TabbedPane.font",
"TabbedPane.background",
"TabbedPane.foreground",
"TabbedPane.lightHighlight",
"TabbedPane.highlight",
"TabbedPane.shadow",
"TabbedPane.darkShadow",
"TabbedPane.focus",
"TabbedPane.textIconGap",
"TabbedPane.tabInsets",
"TabbedPane.selectedTabPadInsets",
"TabbedPane.tabAreaInsets",
"TabbedPane.contentBorderInsets",
"TabbedPane.tabRunOverlay",

"Table.font",
"Table.foreground",
"Table.background",
"Table.selectionForeground",
"Table.selectionBackground",
"Table.gridColor",
"Table.focusCellBackground",
"Table.focusCellForeground",
"Table.focusCellHighlightBorder",
"Table.scrollPaneBorder",
"TableHeader.font",
"TableHeader.foreground",
"TableHeader.background",
"TableHeader.cellBorder",

"TextField.font",
"TextField.background",
"TextField.foreground",
"TextField.inactiveForeground",
"TextField.selectionBackground",
"TextField.selectionForeground",
"TextField.caretForeground",
"TextField.caretBlinkRate",
"TextField.border",
"TextField.margin",
"TextField.keyBindings",

"PasswordField.font",
"PasswordField.background",
"PasswordField.foreground",
"PasswordField.inactiveForeground",
"PasswordField.selectionBackground",
"PasswordField.selectionForeground",
"PasswordField.caretForeground",
"PasswordField.caretBlinkRate",
"PasswordField.border",
"PasswordField.margin",
"PasswordField.keyBindings",

"TextArea.font",
"TextArea.background",
"TextArea.foreground",
"TextArea.inactiveForeground",
"TextArea.selectionBackground",
"TextArea.selectionForeground",
"TextArea.caretForeground",
"TextArea.caretBlinkRate",
"TextArea.border",
"TextArea.margin",
"TextArea.keyBindings",

"TextPane.font",
"TextPane.background",
"TextPane.foreground",
"TextPane.selectionBackground",
"TextPane.selectionForeground",
"TextPane.caretForeground",
"TextPane.caretBlinkRate",
"TextPane.inactiveForeground",
"TextPane.border",
"TextPane.margin",
"TextPane.keyBindings",

"EditorPane.font",
"EditorPane.background",
"EditorPane.foreground",
"EditorPane.selectionBackground",
"EditorPane.selectionForeground",
"EditorPane.caretForeground",
"EditorPane.caretBlinkRate",
"EditorPane.inactiveForeground",
"EditorPane.border",
"EditorPane.margin",
"EditorPane.keyBindings",

"TitledBorder.font",
"TitledBorder.titleColor",
"TitledBorder.border",

"ToolBar.font",
"ToolBar.background",
"ToolBar.foreground",
"ToolBar.dockingBackground",
"ToolBar.dockingForeground",
"ToolBar.floatingBackground",
"ToolBar.floatingForeground",
"ToolBar.border",
"ToolBar.separatorSize",

"ToolTip.font",
"ToolTip.background",
"ToolTip.foreground",
"ToolTip.border",

"Tree.font",
"Tree.background",
"Tree.foreground",
"Tree.hash",
"Tree.textForeground",
"Tree.textBackground",
"Tree.selectionForeground",
"Tree.selectionBackground",
"Tree.selectionBorderColor",
"Tree.editorBorder",
"Tree.leftChildIndent",
"Tree.rightChildIndent",
"Tree.rowHeight",
"Tree.scrollsOnExpand",
"Tree.openIcon",
"Tree.closedIcon",
"Tree.leafIcon",
"Tree.expandedIcon",
"Tree.collapsedIcon",
"Tree.changeSelectionWithFocus",
"Tree.drawsFocusBorderAroundIcon",

[Top]


History

Version: 1 [Mar 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.