Java UIManager color keys

Java color FAQ: Do you have a list of color keys I can use with the Java UIManager class?

Solution

If you're asking this question about the list of color keys in the UIManager class, you probably already know that you can write code like this to use color values from the Java UIManager class:

headerLabel.setForeground(UIManager.getColor("Label.foreground"));

Therefore, I'll jump right in, and say that after digging around for a while, I've been able to figure out how to generate all these UIManager color key values, and I'm glad to share all of those here today.

A Java class to generate the UIManager color keys

Without any further ado, here's a Java class I created to generate a list of all the UIManager color keys:

import java.awt.Color;
import java.util.*;
import java.util.Map.Entry;
import javax.swing.UIManager;

/**
 * Generate a list of UIManager color keys.
 */
public class UIManagerColorKeys
{
  public static void main(String[] args) throws Exception
  {
    List<String> colorKeys = new ArrayList<String>();
    Set<Entry<Object, Object>> entries = UIManager.getLookAndFeelDefaults().entrySet();
    for (Entry entry : entries)
    {
      if (entry.getValue() instanceof Color)
      {
        colorKeys.add((String) entry.getKey());
      }
    }

    // sort the color keys
    Collections.sort(colorKeys);
    
    // print the color keys
    for (String colorKey : colorKeys)
    {
      System.out.println(colorKey);
    }

  }
}

As you can see, that code is fairly simple. I just look for anything the UIManager stores as a Color in its value, and then get the key that corresponds to that Color.

UIManager color key values

And more importantly, here's what you probably came here for -- the output from this class -- which shows all the UIManager color keys:

Button.background
Button.darkShadow
Button.disabledText
Button.foreground
Button.highlight
Button.light
Button.select
Button.shadow
CheckBox.background
CheckBox.disabledText
CheckBox.foreground
CheckBox.select
CheckBoxMenuItem.acceleratorForeground
CheckBoxMenuItem.acceleratorSelectionForeground
CheckBoxMenuItem.background
CheckBoxMenuItem.disabledBackground
CheckBoxMenuItem.disabledForeground
CheckBoxMenuItem.foreground
CheckBoxMenuItem.selectionBackground
CheckBoxMenuItem.selectionForeground
ColorChooser.background
ColorChooser.foreground
ColorChooser.swatchesDefaultRecentColor
ComboBox.background
ComboBox.buttonBackground
ComboBox.buttonDarkShadow
ComboBox.buttonHighlight
ComboBox.buttonShadow
ComboBox.disabledBackground
ComboBox.disabledForeground
ComboBox.foreground
ComboBox.selectionBackground
ComboBox.selectionForeground
Desktop.background
EditorPane.background
EditorPane.caretForeground
EditorPane.foreground
EditorPane.inactiveBackground
EditorPane.inactiveForeground
EditorPane.selectionBackground
EditorPane.selectionForeground
Focus.color
FormattedTextField.background
FormattedTextField.caretForeground
FormattedTextField.foreground
FormattedTextField.inactiveBackground
FormattedTextField.inactiveForeground
FormattedTextField.selectionBackground
FormattedTextField.selectionForeground
InternalFrame.activeTitleBackground
InternalFrame.activeTitleForeground
InternalFrame.background
InternalFrame.borderColor
InternalFrame.borderDarkShadow
InternalFrame.borderHighlight
InternalFrame.borderLight
InternalFrame.borderShadow
InternalFrame.inactiveTitleBackground
InternalFrame.inactiveTitleForeground
InternalFrame.optionDialogBackground
InternalFrame.paletteBackground
Label.background
Label.disabledForeground
Label.disabledShadow
Label.foreground
List.background
List.foreground
List.selectionBackground
List.selectionForeground
Menu.acceleratorForeground
Menu.acceleratorSelectionForeground
Menu.background
Menu.disabledBackground
Menu.disabledForeground
Menu.foreground
Menu.selectionBackground
Menu.selectionForeground
MenuBar.background
MenuBar.disabledBackground
MenuBar.disabledForeground
MenuBar.foreground
MenuBar.highlight
MenuBar.selectionBackground
MenuBar.selectionForeground
MenuBar.shadow
MenuItem.acceleratorForeground
MenuItem.acceleratorSelectionForeground
MenuItem.background
MenuItem.disabledBackground
MenuItem.disabledForeground
MenuItem.foreground
MenuItem.selectionBackground
MenuItem.selectionForeground
OptionPane.background
OptionPane.foreground
OptionPane.messageForeground
Panel.background
Panel.foreground
PasswordField.background
PasswordField.caretForeground
PasswordField.foreground
PasswordField.inactiveBackground
PasswordField.inactiveForeground
PasswordField.selectionBackground
PasswordField.selectionForeground
PopupMenu.background
PopupMenu.foreground
PopupMenu.selectionBackground
PopupMenu.selectionForeground
ProgressBar.background
ProgressBar.foreground
ProgressBar.selectionBackground
ProgressBar.selectionForeground
RadioButton.background
RadioButton.darkShadow
RadioButton.disabledText
RadioButton.foreground
RadioButton.highlight
RadioButton.light
RadioButton.select
RadioButton.shadow
RadioButtonMenuItem.acceleratorForeground
RadioButtonMenuItem.acceleratorSelectionForeground
RadioButtonMenuItem.background
RadioButtonMenuItem.disabledBackground
RadioButtonMenuItem.disabledForeground
RadioButtonMenuItem.foreground
RadioButtonMenuItem.selectionBackground
RadioButtonMenuItem.selectionForeground
ScrollBar.background
ScrollBar.foreground
ScrollBar.thumb
ScrollBar.thumbDarkShadow
ScrollBar.thumbHighlight
ScrollBar.thumbShadow
ScrollBar.track
ScrollBar.trackHighlight
ScrollPane.background
ScrollPane.foreground
Separator.foreground
Separator.highlight
Separator.shadow
Slider.background
Slider.focus
Slider.foreground
Slider.highlight
Slider.shadow
Slider.tickColor
Spinner.background
Spinner.foreground
SplitPane.background
SplitPane.darkShadow
SplitPane.highlight
SplitPane.shadow
SplitPaneDivider.draggingColor
TabbedPane.background
TabbedPane.darkShadow
TabbedPane.focus
TabbedPane.foreground
TabbedPane.highlight
TabbedPane.light
TabbedPane.shadow
Table.background
Table.focusCellBackground
Table.focusCellForeground
Table.foreground
Table.gridColor
Table.selectionBackground
Table.selectionForeground
TableHeader.background
TableHeader.foreground
TextArea.background
TextArea.caretForeground
TextArea.foreground
TextArea.inactiveBackground
TextArea.inactiveForeground
TextArea.selectionBackground
TextArea.selectionForeground
TextComponent.selectionBackgroundInactive
TextField.background
TextField.caretForeground
TextField.darkShadow
TextField.foreground
TextField.highlight
TextField.inactiveBackground
TextField.inactiveForeground
TextField.light
TextField.selectionBackground
TextField.selectionForeground
TextField.shadow
TextPane.background
TextPane.caretForeground
TextPane.foreground
TextPane.inactiveBackground
TextPane.inactiveForeground
TextPane.selectionBackground
TextPane.selectionForeground
TitledBorder.titleColor
ToggleButton.background
ToggleButton.darkShadow
ToggleButton.disabledText
ToggleButton.foreground
ToggleButton.highlight
ToggleButton.light
ToggleButton.shadow
ToolBar.background
ToolBar.darkShadow
ToolBar.dockingBackground
ToolBar.dockingForeground
ToolBar.floatingBackground
ToolBar.floatingForeground
ToolBar.foreground
ToolBar.highlight
ToolBar.light
ToolBar.shadow
ToolTip.background
ToolTip.foreground
Tree.background
Tree.foreground
Tree.hash
Tree.line
Tree.selectionBackground
Tree.selectionBorderColor
Tree.selectionForeground
Tree.textBackground
Tree.textForeground
Viewport.background
Viewport.foreground
activeCaption
activeCaptionBorder
activeCaptionText
control
controlDkShadow
controlHighlight
controlLtHighlight
controlShadow
controlText
desktop
inactiveCaption
inactiveCaptionBorder
inactiveCaptionText
info
infoText
menu
menuText
scrollbar
text
textHighlight
textHighlightText
textInactiveText
textText
window
windowBorder
windowText

UIManager color keys - JFormDesigner color palettes

I'm short on time today, but while I'm in this neighborhood, let me say that I got started on this quest while (a) working on a new Java Swing application, and (b) running into the color palettes that were displayed by a JFormDesigner color chooser. When I saw this list of color keys, I decided to dig under the hood to see what was happening, which led to the class and list of color key output shown above.

As I go, here's a quick image from JFormDesigner that started me on this "UIManager color keys" quest:

Java UIManager color keys - color key values, from JFormDesigner

As mentioned, I really like JFormDesigner, and highly recommend it when designing Java Swing GUI components like JFrame, JDialog, and JPanel components. It's very helpful in many ways, including this simple ability to help you choose the proper UIManager color key values.