javax.swing.plaf.metal

Class MetalLookAndFeel

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, getDefaults, initClassDefaults, initComponentDefaults, initSystemColorDefaults, initialize, loadSystemColors, playSound, uninitialize

Methods inherited from class javax.swing.LookAndFeel

getDefaults, getDescription, getDesktopPropertyValue, getID, getName, getSupportsWindowDecorations, initialize, installBorder, installColors, installColorsAndFont, installProperty, isNativeLookAndFeel, isSupportedLookAndFeel, loadKeyBindings, makeComponentInputMap, makeIcon, makeInputMap, makeKeyBindings, provideErrorFeedback, toString, uninitialize, uninstallBorder

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

MetalLookAndFeel

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

Method Details

createDefaultTheme

protected void createDefaultTheme()
Sets the current theme to a new instance of 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 OceanTheme.
Returns:
The current theme (never null).

getDefaults

public UIDefaults getDefaults()
Creates and returns a new instance of the default resources for this look and feel.
Overrides:
getDefaults in interface BasicLookAndFeel
Returns:
The UI defaults.

getDescription

public String getDescription()
Returns a string describing the look and feel. In this case, the method returns "Metal look and feel".
Overrides:
getDescription in interface LookAndFeel
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.
Overrides:
getID in interface LookAndFeel
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.

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.

getMenuForeground

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

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.

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.

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.
Overrides:
getName in interface LookAndFeel
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.
Overrides:
getSupportsWindowDecorations in interface LookAndFeel
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
ButtonUIMetalButtonUI
CheckBoxUIMetalCheckBoxUI
ComboBoxUIMetalComboBoxUI
DesktopIconUIMetalDesktopIconUI
InternalFrameUIMetalInternalFrameUI
LabelUIMetalLabelUI
PopupMenuSeparatorUIMetalPopupMenuSeparatorUI
ProgressBarUIMetalProgressBarUI
RadioButtonUIMetalRadioButtonUI
RootPaneUIMetalRootPaneUI
ScrollBarUIMetalScrollBarUI
ScrollPaneUIMetalScrollPaneUI
SeparatorUIMetalSeparatorUI
SliderUIMetalSliderUI
SplitPaneUIMetalSplitPaneUI
TabbedPaneUIMetalTabbedPaneUI
TextFieldUIMetalTextFieldUI
ToggleButtonUIMetalToggleButtonUI
ToolBarUIMetalToolBarUI
ToolTipUIMetalToolTipUI
TreeUIMetalTreeUI
Overrides:
initClassDefaults in interface 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.bordernew javax.swing.plaf.metal.MetalBorders.PopupMenuBorder()
Overrides:
initComponentDefaults in interface 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 interface BasicLookAndFeel

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.
Overrides:
isNativeLookAndFeel in interface LookAndFeel
Returns:
false.

isSupportedLookAndFeel

public boolean isSupportedLookAndFeel()
Returns true to indicate that this look and feel is supported on all platforms.
Overrides:
isSupportedLookAndFeel in interface LookAndFeel
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 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.

MetalLookAndFeel.java Copyright (C) 2002, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.