javax.swing.plaf.metal
Class MetalLookAndFeel

java.lang.Object
  extended by javax.swing.LookAndFeel
      extended by javax.swing.plaf.basic.BasicLookAndFeel
          extended by javax.swing.plaf.metal.MetalLookAndFeel
All Implemented Interfaces:
Serializable

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();
 }

See Also:
Serialized Form

Constructor Summary
MetalLookAndFeel()
          Creates a new instance of the Metal look and feel.
 
Method Summary
protected  void createDefaultTheme()
          Sets the current theme to a new instance of DefaultMetalTheme.
static ColorUIResource getAcceleratorForeground()
          Returns the accelerator foreground color from the installed theme.
static ColorUIResource getAcceleratorSelectedForeground()
          Returns the accelerator selected foreground color from the installed theme.
static ColorUIResource getBlack()
          Returns the color black from the installed theme.
static ColorUIResource getControl()
          Returns the control color from the installed theme.
static ColorUIResource getControlDarkShadow()
          Returns the color used for dark shadows on controls, from the installed theme.
static ColorUIResource getControlDisabled()
          Returns the color used for disabled controls, from the installed theme.
static ColorUIResource getControlHighlight()
          Returns the color used to draw highlights for controls, from the installed theme.
static ColorUIResource getControlInfo()
          Returns the color used to display control info, from the installed theme.
static ColorUIResource getControlShadow()
          Returns the color used to draw shadows for controls, from the installed theme.
static ColorUIResource getControlTextColor()
          Returns the color used for text on controls, from the installed theme.
static FontUIResource getControlTextFont()
          Returns the font used for text on controls, from the installed theme.
static MetalTheme getCurrentTheme()
          Returns the current theme for the Metal look and feel.
 UIDefaults getDefaults()
          Creates and returns a new instance of the default resources for this look and feel.
 String getDescription()
          Returns a string describing the look and feel.
static ColorUIResource getDesktopColor()
          Returns the color used for the desktop background, from the installed theme.
static ColorUIResource getFocusColor()
          Returns the color used to draw focus highlights, from the installed theme.
static ColorUIResource getHighlightedTextColor()
          Returns the color used to draw highlighted text, from the installed theme.
 String getID()
          Returns the look and feel identifier.
static ColorUIResource getInactiveControlTextColor()
          Returns the color used to draw text on inactive controls, from the installed theme.
static ColorUIResource getInactiveSystemTextColor()
          Returns the color used to draw inactive system text, from the installed theme.
static ColorUIResource getMenuBackground()
          Returns the background color for menu items, from the installed theme.
static ColorUIResource getMenuDisabledForeground()
          Returns the foreground color for disabled menu items, from the installed theme.
static ColorUIResource getMenuForeground()
          Returns the foreground color for menu items, from the installed theme.
static ColorUIResource getMenuSelectedBackground()
          Returns the background color for selected menu items, from the installed theme.
static ColorUIResource getMenuSelectedForeground()
          Returns the foreground color for selected menu items, from the installed theme.
static FontUIResource getMenuTextFont()
          Returns the font used for text in menus, from the installed theme.
 String getName()
          Returns the look and feel name.
static ColorUIResource getPrimaryControl()
          Returns the primary color for controls, from the installed theme.
static ColorUIResource getPrimaryControlDarkShadow()
          Returns the primary color for the dark shadow on controls, from the installed theme.
static ColorUIResource getPrimaryControlHighlight()
          Returns the primary color for the highlight on controls, from the installed theme.
static ColorUIResource getPrimaryControlInfo()
          Returns the primary color for the information on controls, from the installed theme.
static ColorUIResource getPrimaryControlShadow()
          Returns the primary color for the shadow on controls, from the installed theme.
static ColorUIResource getSeparatorBackground()
          Returns the background color for separators, from the installed theme.
static ColorUIResource getSeparatorForeground()
          Returns the foreground color for separators, from the installed theme.
static FontUIResource getSubTextFont()
          Returns the font used for sub text, from the installed theme.
 boolean getSupportsWindowDecorations()
          Returns true because the Metal look and feel supports window decorations for toplevel containers.
static ColorUIResource getSystemTextColor()
          Returns the color used for system text, from the installed theme.
static FontUIResource getSystemTextFont()
          Returns the font used for system text, from the installed theme.
static ColorUIResource getTextHighlightColor()
          Returns the color used to highlight text, from the installed theme.
static ColorUIResource getUserTextColor()
          Returns the color used to display user text, from the installed theme.
static FontUIResource getUserTextFont()
          Returns the font used for user text, obtained from the current theme.
static ColorUIResource getWhite()
          Returns the color used for white, from the installed theme.
static ColorUIResource getWindowBackground()
          Returns the window background color, from the installed theme.
static ColorUIResource getWindowTitleBackground()
          Returns the window title background color, from the installed theme.
static FontUIResource getWindowTitleFont()
          Returns the window title font from the current theme.
static ColorUIResource getWindowTitleForeground()
          Returns the window title foreground color, from the installed theme.
static ColorUIResource getWindowTitleInactiveBackground()
          Returns the background color for an inactive window title, from the installed theme.
static ColorUIResource getWindowTitleInactiveForeground()
          Returns the foreground color for an inactive window title, from the installed theme.
protected  void initClassDefaults(UIDefaults defaults)
          Sets the ComponentUI classes for all Swing components to the Metal implementations.
protected  void initComponentDefaults(UIDefaults defaults)
          Initializes the component defaults for the Metal Look & Feel.
protected  void initSystemColorDefaults(UIDefaults defaults)
          Initializes the system color defaults.
 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.
 boolean isSupportedLookAndFeel()
          Returns true to indicate that this look and feel is supported on all platforms.
static void setCurrentTheme(MetalTheme theme)
          Sets the current theme for the look and feel.
 
Methods inherited from class javax.swing.plaf.basic.BasicLookAndFeel
createAudioAction, getAudioActionMap, initialize, loadSystemColors, playSound, uninitialize
 
Methods inherited from class javax.swing.LookAndFeel
getDesktopPropertyValue, installBorder, installColors, installColorsAndFont, installProperty, loadKeyBindings, makeComponentInputMap, makeIcon, makeInputMap, makeKeyBindings, provideErrorFeedback, toString, uninstallBorder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 DefaultMetalTheme.


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.

Specified by:
isNativeLookAndFeel in class LookAndFeel
Returns:
false.

isSupportedLookAndFeel

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

Specified by:
isSupportedLookAndFeel in class LookAndFeel
Returns:
true.

getDescription

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

Specified by:
getDescription in class LookAndFeel
Returns:
A string describing the look and feel.

getID

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

Specified by:
getID in class LookAndFeel
Returns:
"MetalLookAndFeel".

getName

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

Specified by:
getName in class LookAndFeel
Returns:
"MetalLookAndFeel".

getDefaults

public UIDefaults getDefaults()
Description copied from class: BasicLookAndFeel
Creates and returns a new instance of the default resources for this look and feel.

Overrides:
getDefaults in class BasicLookAndFeel
Returns:
The UI defaults.

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.

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.

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.

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.

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.

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 MetalLookAndFeel, first set the theme with this method, then create a new instance of MetalLookAndFeel and install it in the usual way (see UIManager.setLookAndFeel(LookAndFeel)).

Parameters:
theme - the theme (null not permitted).
Throws:
NullPointerException - if theme is null.
See Also:
getCurrentTheme()

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
ButtonUIMetalButtonUI
CheckBoxUIMetalCheckBoxUI
ComboBoxUIMetalComboBoxUI
DesktopIconUIMetalDesktopIconUI
InternalFrameUIMetalInternalFrameUI
LabelUIMetalLabelUI
PopupMenuSeparatorUIMetalPopupMenuSeparatorUI
ProgressBarUIMetalProgressBarUI
RadioButtonUIMetalRadioButtonUI
RootPaneUIMetalRootPaneUI
ScrollBarUIMetalScrollBarUI
ScrollPaneUIMetalScrollPaneUI
SeparatorUIMetalSeparatorUI
SliderUIMetalSliderUI
SplitPaneUIMetalSplitPaneUI
TabbedPaneUIMetalTabbedPaneUI
TextFieldUIMetalTextFieldUI
ToggleButtonUIMetalToggleButtonUI
ToolBarUIMetalToolBarUI
ToolTipUIMetalToolTipUI
TreeUIMetalTreeUI

Overrides:
initClassDefaults in class BasicLookAndFeel
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.borderMetalBorders.getButtonBorder()
Button.fontgetControlTextFont()
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.fontgetControlTextFont()
Menu.background0xcccccc
MenuBar.background0xcccccc
MenuItem.background0xcccccc
ScrollBar.background0xcccccc
PopupMenu.border new javax.swing.plaf.metal.MetalBorders.PopupMenuBorder()

Overrides:
initComponentDefaults in class BasicLookAndFeel
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

Overrides:
initSystemColorDefaults in class BasicLookAndFeel
Parameters:
defaults - the defaults table (null not permitted).

getCurrentTheme

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

Returns:
The current theme (never null).
See Also:
setCurrentTheme(MetalTheme)

getSupportsWindowDecorations

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

Overrides:
getSupportsWindowDecorations in class LookAndFeel
Returns:
true