javax.swing.plaf.metal

Class MetalLookAndFeel

public class MetalLookAndFeel extends BasicLookAndFeel

A custom look and feel that is designed to look similar across different operating systems. To install this look and feel, add the following code (or something similar) near the start of your application:

 try
 {
   UIManager.setLookAndFeel(new MetalLookAndFeel());
 }
 catch (UnsupportedLookAndFeelException e)
 {
   e.printStackTrace();
 }
Constructor Summary
MetalLookAndFeel()
Creates a new instance of the Metal look and feel.
Method Summary
protected voidcreateDefaultTheme()
Sets the current theme to a new instance of {@link DefaultMetalTheme}.
static ColorUIResourcegetAcceleratorForeground()
Returns the accelerator foreground color from the installed theme.
static ColorUIResourcegetAcceleratorSelectedForeground()
Returns the accelerator selected foreground color from the installed theme.
static ColorUIResourcegetBlack()
Returns the color black from the installed theme.
static ColorUIResourcegetControl()
Returns the control color from the installed theme.
static ColorUIResourcegetControlDarkShadow()
Returns the color used for dark shadows on controls, from the installed theme.
static ColorUIResourcegetControlDisabled()
Returns the color used for disabled controls, from the installed theme.
static ColorUIResourcegetControlHighlight()
Returns the color used to draw highlights for controls, from the installed theme.
static ColorUIResourcegetControlInfo()
Returns the color used to display control info, from the installed theme.
static ColorUIResourcegetControlShadow()
Returns the color used to draw shadows for controls, from the installed theme.
static ColorUIResourcegetControlTextColor()
Returns the color used for text on controls, from the installed theme.
static FontUIResourcegetControlTextFont()
Returns the font used for text on controls, from the installed theme.
static MetalThemegetCurrentTheme()
Returns the current theme for the Metal look and feel.
UIDefaultsgetDefaults()
StringgetDescription()
Returns a string describing the look and feel.
static ColorUIResourcegetDesktopColor()
Returns the color used for the desktop background, from the installed theme.
static ColorUIResourcegetFocusColor()
Returns the color used to draw focus highlights, from the installed theme.
static ColorUIResourcegetHighlightedTextColor()
Returns the color used to draw highlighted text, from the installed theme.
StringgetID()
Returns the look and feel identifier.
static ColorUIResourcegetInactiveControlTextColor()
Returns the color used to draw text on inactive controls, from the installed theme.
static ColorUIResourcegetInactiveSystemTextColor()
Returns the color used to draw inactive system text, from the installed theme.
static ColorUIResourcegetMenuBackground()
Returns the background color for menu items, from the installed theme.
static ColorUIResourcegetMenuDisabledForeground()
Returns the foreground color for disabled menu items, from the installed theme.
static ColorUIResourcegetMenuForeground()
Returns the foreground color for menu items, from the installed theme.
static ColorUIResourcegetMenuSelectedBackground()
Returns the background color for selected menu items, from the installed theme.
static ColorUIResourcegetMenuSelectedForeground()
Returns the foreground color for selected menu items, from the installed theme.
static FontUIResourcegetMenuTextFont()
Returns the font used for text in menus, from the installed theme.
StringgetName()
Returns the look and feel name.
static ColorUIResourcegetPrimaryControl()
Returns the primary color for controls, from the installed theme.
static ColorUIResourcegetPrimaryControlDarkShadow()
Returns the primary color for the dark shadow on controls, from the installed theme.
static ColorUIResourcegetPrimaryControlHighlight()
Returns the primary color for the highlight on controls, from the installed theme.
static ColorUIResourcegetPrimaryControlInfo()
Returns the primary color for the information on controls, from the installed theme.
static ColorUIResourcegetPrimaryControlShadow()
Returns the primary color for the shadow on controls, from the installed theme.
static ColorUIResourcegetSeparatorBackground()
Returns the background color for separators, from the installed theme.
static ColorUIResourcegetSeparatorForeground()
Returns the foreground color for separators, from the installed theme.
static FontUIResourcegetSubTextFont()
Returns the font used for sub text, from the installed theme.
booleangetSupportsWindowDecorations()
Returns true because the Metal look and feel supports window decorations for toplevel containers.
static ColorUIResourcegetSystemTextColor()
Returns the color used for system text, from the installed theme.
static FontUIResourcegetSystemTextFont()
Returns the font used for system text, from the installed theme.
static ColorUIResourcegetTextHighlightColor()
Returns the color used to highlight text, from the installed theme.
static ColorUIResourcegetUserTextColor()
Returns the color used to display user text, from the installed theme.
static FontUIResourcegetUserTextFont()
Returns the font used for user text, obtained from the current theme.
static ColorUIResourcegetWhite()
Returns the color used for white, from the installed theme.
static ColorUIResourcegetWindowBackground()
Returns the window background color, from the installed theme.
static ColorUIResourcegetWindowTitleBackground()
Returns the window title background color, from the installed theme.
static FontUIResourcegetWindowTitleFont()
Returns the window title font from the current theme.
static ColorUIResourcegetWindowTitleForeground()
Returns the window title foreground color, from the installed theme.
static ColorUIResourcegetWindowTitleInactiveBackground()
Returns the background color for an inactive window title, from the installed theme.
static ColorUIResourcegetWindowTitleInactiveForeground()
Returns the foreground color for an inactive window title, from the installed theme.
protected voidinitClassDefaults(UIDefaults defaults)
Sets the ComponentUI classes for all Swing components to the Metal implementations.
protected voidinitComponentDefaults(UIDefaults defaults)
Initializes the component defaults for the Metal Look & Feel.
protected voidinitSystemColorDefaults(UIDefaults defaults)
Initializes the system color defaults.
booleanisNativeLookAndFeel()
Returns false to indicate that this look and feel does not attempt to emulate the look and feel of native applications on the host platform.
booleanisSupportedLookAndFeel()
Returns true to indicate that this look and feel is supported on all platforms.
static voidsetCurrentTheme(MetalTheme theme)
Sets the current theme for the look and feel.

Constructor Detail

MetalLookAndFeel

public MetalLookAndFeel()
Creates a new instance of the Metal look and feel.

Method Detail

createDefaultTheme

protected void createDefaultTheme()
Sets the current theme to a new instance of {@link DefaultMetalTheme}.

getAcceleratorForeground

public static ColorUIResource getAcceleratorForeground()
Returns the accelerator foreground color from the installed theme.

Returns: The accelerator foreground color.

getAcceleratorSelectedForeground

public static ColorUIResource getAcceleratorSelectedForeground()
Returns the accelerator selected foreground color from the installed theme.

Returns: The accelerator selected foreground color.

getBlack

public static ColorUIResource getBlack()
Returns the color black from the installed theme.

Returns: The color black.

getControl

public static ColorUIResource getControl()
Returns the control color from the installed theme.

Returns: The control color.

getControlDarkShadow

public static ColorUIResource getControlDarkShadow()
Returns the color used for dark shadows on controls, from the installed theme.

Returns: The color used for dark shadows on controls.

getControlDisabled

public static ColorUIResource getControlDisabled()
Returns the color used for disabled controls, from the installed theme.

Returns: The color used for disabled controls.

getControlHighlight

public static ColorUIResource getControlHighlight()
Returns the color used to draw highlights for controls, from the installed theme.

Returns: The color used to draw highlights for controls.

getControlInfo

public static ColorUIResource getControlInfo()
Returns the color used to display control info, from the installed theme.

Returns: The color used to display control info.

getControlShadow

public static ColorUIResource getControlShadow()
Returns the color used to draw shadows for controls, from the installed theme.

Returns: The color used to draw shadows for controls.

getControlTextColor

public static ColorUIResource getControlTextColor()
Returns the color used for text on controls, from the installed theme.

Returns: The color used for text on controls.

getControlTextFont

public static FontUIResource getControlTextFont()
Returns the font used for text on controls, from the installed theme.

Returns: The font used for text on controls.

getCurrentTheme

public static MetalTheme getCurrentTheme()
Returns the current theme for the Metal look and feel. The default is an instance of {@link OceanTheme}.

Returns: The current theme (never null).

See Also: setCurrentTheme

getDefaults

public UIDefaults getDefaults()

getDescription

public String getDescription()
Returns a string describing the look and feel. In this case, the method returns "Metal look and feel".

Returns: A string describing the look and feel.

getDesktopColor

public static ColorUIResource getDesktopColor()
Returns the color used for the desktop background, from the installed theme.

Returns: The color used for the desktop background.

getFocusColor

public static ColorUIResource getFocusColor()
Returns the color used to draw focus highlights, from the installed theme.

Returns: The color used to draw focus highlights.

getHighlightedTextColor

public static ColorUIResource getHighlightedTextColor()
Returns the color used to draw highlighted text, from the installed theme.

Returns: The color used to draw highlighted text.

getID

public String getID()
Returns the look and feel identifier.

Returns: "MetalLookAndFeel".

getInactiveControlTextColor

public static ColorUIResource getInactiveControlTextColor()
Returns the color used to draw text on inactive controls, from the installed theme.

Returns: The color used to draw text on inactive controls.

getInactiveSystemTextColor

public static ColorUIResource getInactiveSystemTextColor()
Returns the color used to draw inactive system text, from the installed theme.

Returns: The color used to draw inactive system text.

getMenuBackground

public static ColorUIResource getMenuBackground()
Returns the background color for menu items, from the installed theme.

Returns: The background color for menu items.

See Also: getMenuSelectedBackground

getMenuDisabledForeground

public static ColorUIResource getMenuDisabledForeground()
Returns the foreground color for disabled menu items, from the installed theme.

Returns: The foreground color for disabled menu items.

See Also: getMenuForeground

getMenuForeground

public static ColorUIResource getMenuForeground()
Returns the foreground color for menu items, from the installed theme.

Returns: The foreground color for menu items.

See Also: getMenuDisabledForeground getMenuSelectedForeground

getMenuSelectedBackground

public static ColorUIResource getMenuSelectedBackground()
Returns the background color for selected menu items, from the installed theme.

Returns: The background color for selected menu items.

See Also: getMenuBackground

getMenuSelectedForeground

public static ColorUIResource getMenuSelectedForeground()
Returns the foreground color for selected menu items, from the installed theme.

Returns: The foreground color for selected menu items.

See Also: getMenuForeground

getMenuTextFont

public static FontUIResource getMenuTextFont()
Returns the font used for text in menus, from the installed theme.

Returns: The font used for text in menus.

getName

public String getName()
Returns the look and feel name.

Returns: "MetalLookAndFeel".

getPrimaryControl

public static ColorUIResource getPrimaryControl()
Returns the primary color for controls, from the installed theme.

Returns: The primary color for controls.

getPrimaryControlDarkShadow

public static ColorUIResource getPrimaryControlDarkShadow()
Returns the primary color for the dark shadow on controls, from the installed theme.

Returns: The primary color for the dark shadow on controls.

getPrimaryControlHighlight

public static ColorUIResource getPrimaryControlHighlight()
Returns the primary color for the highlight on controls, from the installed theme.

Returns: The primary color for the highlight on controls.

getPrimaryControlInfo

public static ColorUIResource getPrimaryControlInfo()
Returns the primary color for the information on controls, from the installed theme.

Returns: The primary color for the information on controls.

getPrimaryControlShadow

public static ColorUIResource getPrimaryControlShadow()
Returns the primary color for the shadow on controls, from the installed theme.

Returns: The primary color for the shadow on controls.

getSeparatorBackground

public static ColorUIResource getSeparatorBackground()
Returns the background color for separators, from the installed theme.

Returns: The background color for separators.

getSeparatorForeground

public static ColorUIResource getSeparatorForeground()
Returns the foreground color for separators, from the installed theme.

Returns: The foreground color for separators.

getSubTextFont

public static FontUIResource getSubTextFont()
Returns the font used for sub text, from the installed theme.

Returns: The font used for sub text.

getSupportsWindowDecorations

public boolean getSupportsWindowDecorations()
Returns true because the Metal look and feel supports window decorations for toplevel containers.

Returns: true

getSystemTextColor

public static ColorUIResource getSystemTextColor()
Returns the color used for system text, from the installed theme.

Returns: The color used for system text.

getSystemTextFont

public static FontUIResource getSystemTextFont()
Returns the font used for system text, from the installed theme.

Returns: The font used for system text.

getTextHighlightColor

public static ColorUIResource getTextHighlightColor()
Returns the color used to highlight text, from the installed theme.

Returns: The color used to highlight text.

getUserTextColor

public static ColorUIResource getUserTextColor()
Returns the color used to display user text, from the installed theme.

Returns: The color used to display user text.

getUserTextFont

public static FontUIResource getUserTextFont()
Returns the font used for user text, obtained from the current theme.

Returns: The font used for user text.

getWhite

public static ColorUIResource getWhite()
Returns the color used for white, from the installed theme.

Returns: The color used for white.

getWindowBackground

public static ColorUIResource getWindowBackground()
Returns the window background color, from the installed theme.

Returns: The window background color.

getWindowTitleBackground

public static ColorUIResource getWindowTitleBackground()
Returns the window title background color, from the installed theme.

Returns: The window title background color.

getWindowTitleFont

public static FontUIResource getWindowTitleFont()
Returns the window title font from the current theme.

Returns: The window title font.

See Also: MetalTheme

getWindowTitleForeground

public static ColorUIResource getWindowTitleForeground()
Returns the window title foreground color, from the installed theme.

Returns: The window title foreground color.

getWindowTitleInactiveBackground

public static ColorUIResource getWindowTitleInactiveBackground()
Returns the background color for an inactive window title, from the installed theme.

Returns: The background color for an inactive window title.

getWindowTitleInactiveForeground

public static ColorUIResource getWindowTitleInactiveForeground()
Returns the foreground color for an inactive window title, from the installed theme.

Returns: The foreground color for an inactive window title.

initClassDefaults

protected void initClassDefaults(UIDefaults defaults)
Sets the ComponentUI classes for all Swing components to the Metal implementations. In particular this sets the following keys:
KeyValue
ButtonUI{@link MetalButtonUI}
CheckBoxUI{@link MetalCheckBoxUI}
ComboBoxUI{@link MetalComboBoxUI}
DesktopIconUI{@link MetalDesktopIconUI}
InternalFrameUI{@link MetalInternalFrameUI}
LabelUI{@link MetalLabelUI}
PopupMenuSeparatorUI{@link MetalPopupMenuSeparatorUI}
ProgressBarUI{@link MetalProgressBarUI}
RadioButtonUI{@link MetalRadioButtonUI}
RootPaneUI{@link MetalRootPaneUI}
ScrollBarUI{@link MetalScrollBarUI}
ScrollPaneUI{@link MetalScrollPaneUI}
SeparatorUI{@link MetalSeparatorUI}
SliderUI{@link MetalSliderUI}
SplitPaneUI{@link MetalSplitPaneUI}
TabbedPaneUI{@link MetalTabbedPaneUI}
TextFieldUI{@link MetalTextFieldUI}
ToggleButtonUI{@link MetalToggleButtonUI}
ToolBarUI{@link MetalToolBarUI}
ToolTipUI{@link MetalToolTipUI}
TreeUI{@link MetalTreeUI}

Parameters: defaults the UIDefaults where the class defaults are added

initComponentDefaults

protected void initComponentDefaults(UIDefaults defaults)
Initializes the component defaults for the Metal Look & Feel. In particular this sets the following keys (the colors are given as RGB hex values):
KeyValue
Button.background0xcccccc
Button.border{@link MetalBorders#getButtonBorder()}
Button.font{@link #getControlTextFont}
Button.marginnew java.awt.Insets(2, 14, 2, 14)
CheckBox.background0xcccccc
CheckBoxMenuItem.background0xcccccc
ToolBar.background0xcccccc
Panel.background0xcccccc
Slider.background0xcccccc
OptionPane.background0xcccccc
ProgressBar.background0xcccccc
TabbedPane.background0xcccccc
Label.background0xcccccc
Label.font{@link #getControlTextFont}
Menu.background0xcccccc
MenuBar.background0xcccccc
MenuItem.background0xcccccc
ScrollBar.background0xcccccc
PopupMenu.border new javax.swing.plaf.metal.MetalBorders.PopupMenuBorder()

Parameters: defaults the UIDefaults instance to which the values are added

initSystemColorDefaults

protected void initSystemColorDefaults(UIDefaults defaults)
Initializes the system color defaults. In particular this sets the following keys:
KeyValueDescription
control0xccccccThe default color for components

isNativeLookAndFeel

public boolean isNativeLookAndFeel()
Returns false to indicate that this look and feel does not attempt to emulate the look and feel of native applications on the host platform.

Returns: false.

isSupportedLookAndFeel

public boolean isSupportedLookAndFeel()
Returns true to indicate that this look and feel is supported on all platforms.

Returns: true.

setCurrentTheme

public static void setCurrentTheme(MetalTheme theme)
Sets the current theme for the look and feel. Note that the theme must be set before the look and feel is installed. To change the theme for an already running application that is using the {@link MetalLookAndFeel}, first set the theme with this method, then create a new instance of {@link MetalLookAndFeel} and install it in the usual way (see {@link UIManager#setLookAndFeel(LookAndFeel)}).

Parameters: theme the theme (null not permitted).

Throws: NullPointerException if theme is null.

See Also: getCurrentTheme