W3cubDocs

/OpenJDK 21

Class MetalLookAndFeel

All Implemented Interfaces:
Serializable
public class MetalLookAndFeel extends BasicLookAndFeel
The Java Look and Feel, otherwise known as Metal.

Each of the ComponentUIs provided by MetalLookAndFeel derives its behavior from the defaults table. Unless otherwise noted each of the ComponentUI implementations in this package document the set of defaults they use. Unless otherwise noted the defaults are installed at the time installUI is invoked, and follow the recommendations outlined in LookAndFeel for installing defaults.

MetalLookAndFeel derives it's color palette and fonts from MetalTheme. The default theme is OceanTheme. The theme can be changed using the setCurrentTheme method, refer to it for details on changing the theme. Prior to 1.5 the default theme was DefaultMetalTheme. The system property "swing.metalTheme" can be set to "steel" to indicate the default should be DefaultMetalTheme.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder.

See Also:

Constructor Summary

Constructor Description
MetalLookAndFeel()
Constructs a MetalLookAndFeel.

Method Summary

Modifier and Type Method Description
protected void createDefaultTheme()
Ensures the current MetalTheme is non-null.
static ColorUIResource getAcceleratorForeground()
Returns the accelerator foreground color of the current theme.
static ColorUIResource getAcceleratorSelectedForeground()
Returns the accelerator selected foreground color of the current theme.
static ColorUIResource getBlack()
Returns the black color of the current theme.
static ColorUIResource getControl()
Returns the control color of the current theme.
static ColorUIResource getControlDarkShadow()
Returns the control dark shadow color of the current theme.
static ColorUIResource getControlDisabled()
Returns the control disabled color of the current theme.
static ColorUIResource getControlHighlight()
Returns the control highlight color of the current theme.
static ColorUIResource getControlInfo()
Returns the control info color of the current theme.
static ColorUIResource getControlShadow()
Returns the control shadow color of the current theme.
static ColorUIResource getControlTextColor()
Returns the control text color of the current theme.
static FontUIResource getControlTextFont()
Returns the control text font of the current theme.
static MetalTheme getCurrentTheme()
Return the theme currently being used by MetalLookAndFeel.
UIDefaults getDefaults()
Returns the look and feel defaults.
String getDescription()
Returns a short description of this look and feel.
static ColorUIResource getDesktopColor()
Returns the desktop color of the current theme.
Icon getDisabledIcon(JComponent component, Icon icon)
Returns an Icon with a disabled appearance.
Icon getDisabledSelectedIcon(JComponent component, Icon icon)
Returns an Icon for use by disabled components that are also selected.
static ColorUIResource getFocusColor()
Returns the focus color of the current theme.
static ColorUIResource getHighlightedTextColor()
Returns the highlighted text color of the current theme.
String getID()
Returns an identifier for this look and feel.
static ColorUIResource getInactiveControlTextColor()
Returns the inactive control text color of the current theme.
static ColorUIResource getInactiveSystemTextColor()
Returns the inactive system text color of the current theme.
LayoutStyle getLayoutStyle()
Returns a LayoutStyle implementing the Java look and feel design guidelines.
static ColorUIResource getMenuBackground()
Returns the menu background color of the current theme.
static ColorUIResource getMenuDisabledForeground()
Returns the menu disabled foreground color of the current theme.
static ColorUIResource getMenuForeground()
Returns the menu foreground color of the current theme.
static ColorUIResource getMenuSelectedBackground()
Returns the menu selected background color of the current theme.
static ColorUIResource getMenuSelectedForeground()
Returns the menu selected foreground color of the current theme.
static FontUIResource getMenuTextFont()
Returns the menu text font of the current theme.
String getName()
Returns the name of this look and feel.
static ColorUIResource getPrimaryControl()
Returns the primary control color of the current theme.
static ColorUIResource getPrimaryControlDarkShadow()
Returns the primary control dark shadow color of the current theme.
static ColorUIResource getPrimaryControlHighlight()
Returns the primary control highlight color of the current theme.
static ColorUIResource getPrimaryControlInfo()
Returns the primary control info color of the current theme.
static ColorUIResource getPrimaryControlShadow()
Returns the primary control shadow color of the current theme.
static ColorUIResource getSeparatorBackground()
Returns the separator background color of the current theme.
static ColorUIResource getSeparatorForeground()
Returns the separator foreground color of the current theme.
static FontUIResource getSubTextFont()
Returns the sub-text font of the current theme.
boolean getSupportsWindowDecorations()
Returns true; metal can provide Window decorations.
static ColorUIResource getSystemTextColor()
Returns the system text color of the current theme.
static FontUIResource getSystemTextFont()
Returns the system text font of the current theme.
static ColorUIResource getTextHighlightColor()
Returns the text highlight color of the current theme.
static ColorUIResource getUserTextColor()
Returns the user text color of the current theme.
static FontUIResource getUserTextFont()
Returns the user text font of the current theme.
static ColorUIResource getWhite()
Returns the white color of the current theme.
static ColorUIResource getWindowBackground()
Returns the window background color of the current theme.
static ColorUIResource getWindowTitleBackground()
Returns the window title background color of the current theme.
static FontUIResource getWindowTitleFont()
Returns the window title font of the current theme.
static ColorUIResource getWindowTitleForeground()
Returns the window title foreground color of the current theme.
static ColorUIResource getWindowTitleInactiveBackground()
Returns the window title inactive background color of the current theme.
static ColorUIResource getWindowTitleInactiveForeground()
Returns the window title inactive foreground color of the current theme.
protected void initClassDefaults(UIDefaults table)
Populates table with mappings from uiClassID to the fully qualified name of the ui class.
protected void initComponentDefaults(UIDefaults table)
Populates table with the defaults for metal.
protected void initSystemColorDefaults(UIDefaults table)
Populates table with system colors.
boolean isNativeLookAndFeel()
Returns false; MetalLookAndFeel is not a native look and feel.
boolean isSupportedLookAndFeel()
Returns true; MetalLookAndFeel can be run on any platform.
void provideErrorFeedback(Component component)
Invoked when the user attempts an invalid operation, such as pasting into an uneditable JTextField that has focus.
static void setCurrentTheme(MetalTheme theme)
Set the theme used by MetalLookAndFeel.

Methods declared in class javax.swing.plaf.basic.BasicLookAndFeel

createAudioAction, getAudioActionMap, loadSystemColors, playSound

Methods declared in class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Details

MetalLookAndFeel

public MetalLookAndFeel()
Constructs a MetalLookAndFeel.

Method Details

getName

public String getName()
Returns the name of this look and feel. This returns "Metal".
Specified by:
getName in class LookAndFeel
Returns:
the name of this look and feel

getID

public String getID()
Returns an identifier for this look and feel. This returns "Metal".
Specified by:
getID in class LookAndFeel
Returns:
the identifier of this look and feel

getDescription

public String getDescription()
Returns a short description of this look and feel. This returns "The Java(tm) Look and Feel".
Specified by:
getDescription in class LookAndFeel
Returns:
a short description for the look and feel

isNativeLookAndFeel

public boolean isNativeLookAndFeel()
Returns false; MetalLookAndFeel is not a native look and feel.
Specified by:
isNativeLookAndFeel in class LookAndFeel
Returns:
false

isSupportedLookAndFeel

public boolean isSupportedLookAndFeel()
Returns true; MetalLookAndFeel can be run on any platform.
Specified by:
isSupportedLookAndFeel in class LookAndFeel
Returns:
true
See Also:

getSupportsWindowDecorations

public boolean getSupportsWindowDecorations()
Returns true; metal can provide Window decorations.
Overrides:
getSupportsWindowDecorations in class LookAndFeel
Returns:
true
Since:
1.4
See Also:

initClassDefaults

protected void initClassDefaults(UIDefaults table)
Populates table with mappings from uiClassID to the fully qualified name of the ui class. MetalLookAndFeel registers an entry for each of the classes in the package javax.swing.plaf.metal that are named MetalXXXUI. The string XXX is one of Swing's uiClassIDs. For the uiClassIDs that do not have a class in metal, the corresponding class in javax.swing.plaf.basic is used. For example, metal does not have a class named "MetalColorChooserUI", as such, javax.swing.plaf.basic.BasicColorChooserUI is used.
Overrides:
initClassDefaults in class BasicLookAndFeel
Parameters:
table - the UIDefaults instance the entries are added to
Throws:
NullPointerException - if table is null
See Also:

initSystemColorDefaults

protected void initSystemColorDefaults(UIDefaults table)
Populates table with system colors. The following values are added to table:
Metal's system color mapping
Key Value
"desktop" theme.getDesktopColor()
"activeCaption" theme.getWindowTitleBackground()
"activeCaptionText" theme.getWindowTitleForeground()
"activeCaptionBorder" theme.getPrimaryControlShadow()
"inactiveCaption" theme.getWindowTitleInactiveBackground()
"inactiveCaptionText" theme.getWindowTitleInactiveForeground()
"inactiveCaptionBorder" theme.getControlShadow()
"window" theme.getWindowBackground()
"windowBorder" theme.getControl()
"windowText" theme.getUserTextColor()
"menu" theme.getMenuBackground()
"menuText" theme.getMenuForeground()
"text" theme.getWindowBackground()
"textText" theme.getUserTextColor()
"textHighlight" theme.getTextHighlightColor()
"textHighlightText" theme.getHighlightedTextColor()
"textInactiveText" theme.getInactiveSystemTextColor()
"control" theme.getControl()
"controlText" theme.getControlTextColor()
"controlHighlight" theme.getControlHighlight()
"controlLtHighlight" theme.getControlHighlight()
"controlShadow" theme.getControlShadow()
"controlDkShadow" theme.getControlDarkShadow()
"scrollbar" theme.getControl()
"info" theme.getPrimaryControl()
"infoText" theme.getPrimaryControlInfo()
The value theme corresponds to the current MetalTheme.
Overrides:
initSystemColorDefaults in class BasicLookAndFeel
Parameters:
table - the UIDefaults object the values are added to
Throws:
NullPointerException - if table is null
See Also:

initComponentDefaults

protected void initComponentDefaults(UIDefaults table)
Populates table with the defaults for metal.
Overrides:
initComponentDefaults in class BasicLookAndFeel
Parameters:
table - the UIDefaults to add the values to
Throws:
NullPointerException - if table is null

createDefaultTheme

protected void createDefaultTheme()
Ensures the current MetalTheme is non-null. This is a cover method for getCurrentTheme.
See Also:

getDefaults

public UIDefaults getDefaults()
Returns the look and feel defaults. This invokes, in order, createDefaultTheme(), super.getDefaults() and getCurrentTheme().addCustomEntriesToTable(table).

While this method is public, it should only be invoked by the UIManager when the look and feel is set as the current look and feel and after initialize has been invoked.

Overrides:
getDefaults in class BasicLookAndFeel
Returns:
the look and feel defaults
See Also:

provideErrorFeedback

public void provideErrorFeedback(Component component)
Invoked when the user attempts an invalid operation, such as pasting into an uneditable JTextField that has focus. The default implementation beeps. Subclasses that wish different behavior should override this and provide the additional feedback.
Overrides:
provideErrorFeedback in class LookAndFeel
Parameters:
component - the Component the error occurred in, may be null indicating the error condition is not directly associated with a Component
Since:
1.4

setCurrentTheme

public static void setCurrentTheme(MetalTheme theme)
Set the theme used by MetalLookAndFeel.

After the theme is set, MetalLookAndFeel needs to be re-installed and the uis need to be recreated. The following shows how to do this:

   MetalLookAndFeel.setCurrentTheme(theme);

   // re-install the Metal Look and Feel
   UIManager.setLookAndFeel(new MetalLookAndFeel());

   // Update the ComponentUIs for all Components. This
   // needs to be invoked for all windows.
   SwingUtilities.updateComponentTreeUI(rootComponent);
 
If this is not done the results are undefined.
Parameters:
theme - the theme to use
Throws:
NullPointerException - if theme is null
See Also:

getCurrentTheme

public static MetalTheme getCurrentTheme()
Return the theme currently being used by MetalLookAndFeel. If the current theme is null, the default theme is created.
Returns:
the current theme
Since:
1.5
See Also:

getDisabledIcon

public Icon getDisabledIcon(JComponent component, Icon icon)
Returns an Icon with a disabled appearance. This method is used to generate a disabled Icon when one has not been specified. For example, if you create a JButton and only specify an Icon via setIcon this method will be called to generate the disabled Icon. If null is passed as icon this method returns null.

Some look and feels might not render the disabled Icon, in which case they will ignore this.

Overrides:
getDisabledIcon in class LookAndFeel
Parameters:
component - JComponent that will display the Icon, may be null
icon - Icon to generate disable icon from.
Returns:
Disabled icon, or null if a suitable Icon can not be generated.
Since:
1.5

getDisabledSelectedIcon

public Icon getDisabledSelectedIcon(JComponent component, Icon icon)
Returns an Icon for use by disabled components that are also selected. This method is used to generate an Icon for components that are in both the disabled and selected states but do not have a specific Icon for this state. For example, if you create a JButton and only specify an Icon via setIcon this method will be called to generate the disabled and selected Icon. If null is passed as icon this method returns null.

Some look and feels might not render the disabled and selected Icon, in which case they will ignore this.

Overrides:
getDisabledSelectedIcon in class LookAndFeel
Parameters:
component - JComponent that will display the Icon, may be null
icon - Icon to generate disabled and selected icon from.
Returns:
Disabled and Selected icon, or null if a suitable Icon can not be generated.
Since:
1.5

getControlTextFont

public static FontUIResource getControlTextFont()
Returns the control text font of the current theme. This is a cover method for getCurrentTheme().getControlTextColor().
Returns:
the control text font
See Also:

getSystemTextFont

public static FontUIResource getSystemTextFont()
Returns the system text font of the current theme. This is a cover method for getCurrentTheme().getSystemTextFont().
Returns:
the system text font
See Also:

getUserTextFont

public static FontUIResource getUserTextFont()
Returns the user text font of the current theme. This is a cover method for getCurrentTheme().getUserTextFont().
Returns:
the user text font
See Also:

getMenuTextFont

public static FontUIResource getMenuTextFont()
Returns the menu text font of the current theme. This is a cover method for getCurrentTheme().getMenuTextFont().
Returns:
the menu text font
See Also:

getWindowTitleFont

public static FontUIResource getWindowTitleFont()
Returns the window title font of the current theme. This is a cover method for getCurrentTheme().getWindowTitleFont().
Returns:
the window title font
See Also:

getSubTextFont

public static FontUIResource getSubTextFont()
Returns the sub-text font of the current theme. This is a cover method for getCurrentTheme().getSubTextFont().
Returns:
the sub-text font
See Also:

getDesktopColor

public static ColorUIResource getDesktopColor()
Returns the desktop color of the current theme. This is a cover method for getCurrentTheme().getDesktopColor().
Returns:
the desktop color
See Also:

getFocusColor

public static ColorUIResource getFocusColor()
Returns the focus color of the current theme. This is a cover method for getCurrentTheme().getFocusColor().
Returns:
the focus color
See Also:

getWhite

public static ColorUIResource getWhite()
Returns the white color of the current theme. This is a cover method for getCurrentTheme().getWhite().
Returns:
the white color
See Also:

getBlack

public static ColorUIResource getBlack()
Returns the black color of the current theme. This is a cover method for getCurrentTheme().getBlack().
Returns:
the black color
See Also:

getControl

public static ColorUIResource getControl()
Returns the control color of the current theme. This is a cover method for getCurrentTheme().getControl().
Returns:
the control color
See Also:

getControlShadow

public static ColorUIResource getControlShadow()
Returns the control shadow color of the current theme. This is a cover method for getCurrentTheme().getControlShadow().
Returns:
the control shadow color
See Also:

getControlDarkShadow

public static ColorUIResource getControlDarkShadow()
Returns the control dark shadow color of the current theme. This is a cover method for getCurrentTheme().getControlDarkShadow().
Returns:
the control dark shadow color
See Also:

getControlInfo

public static ColorUIResource getControlInfo()
Returns the control info color of the current theme. This is a cover method for getCurrentTheme().getControlInfo().
Returns:
the control info color
See Also:

getControlHighlight

public static ColorUIResource getControlHighlight()
Returns the control highlight color of the current theme. This is a cover method for getCurrentTheme().getControlHighlight().
Returns:
the control highlight color
See Also:

getControlDisabled

public static ColorUIResource getControlDisabled()
Returns the control disabled color of the current theme. This is a cover method for getCurrentTheme().getControlDisabled().
Returns:
the control disabled color
See Also:

getPrimaryControl

public static ColorUIResource getPrimaryControl()
Returns the primary control color of the current theme. This is a cover method for getCurrentTheme().getPrimaryControl().
Returns:
the primary control color
See Also:

getPrimaryControlShadow

public static ColorUIResource getPrimaryControlShadow()
Returns the primary control shadow color of the current theme. This is a cover method for getCurrentTheme().getPrimaryControlShadow().
Returns:
the primary control shadow color
See Also:

getPrimaryControlDarkShadow

public static ColorUIResource getPrimaryControlDarkShadow()
Returns the primary control dark shadow color of the current theme. This is a cover method for getCurrentTheme().getPrimaryControlDarkShadow().
Returns:
the primary control dark shadow color
See Also:

getPrimaryControlInfo

public static ColorUIResource getPrimaryControlInfo()
Returns the primary control info color of the current theme. This is a cover method for getCurrentTheme().getPrimaryControlInfo().
Returns:
the primary control info color
See Also:

getPrimaryControlHighlight

public static ColorUIResource getPrimaryControlHighlight()
Returns the primary control highlight color of the current theme. This is a cover method for getCurrentTheme().getPrimaryControlHighlight().
Returns:
the primary control highlight color
See Also:

getSystemTextColor

public static ColorUIResource getSystemTextColor()
Returns the system text color of the current theme. This is a cover method for getCurrentTheme().getSystemTextColor().
Returns:
the system text color
See Also:

getControlTextColor

public static ColorUIResource getControlTextColor()
Returns the control text color of the current theme. This is a cover method for getCurrentTheme().getControlTextColor().
Returns:
the control text color
See Also:

getInactiveControlTextColor

public static ColorUIResource getInactiveControlTextColor()
Returns the inactive control text color of the current theme. This is a cover method for getCurrentTheme().getInactiveControlTextColor().
Returns:
the inactive control text color
See Also:

getInactiveSystemTextColor

public static ColorUIResource getInactiveSystemTextColor()
Returns the inactive system text color of the current theme. This is a cover method for getCurrentTheme().getInactiveSystemTextColor().
Returns:
the inactive system text color
See Also:

getUserTextColor

public static ColorUIResource getUserTextColor()
Returns the user text color of the current theme. This is a cover method for getCurrentTheme().getUserTextColor().
Returns:
the user text color
See Also:

getTextHighlightColor

public static ColorUIResource getTextHighlightColor()
Returns the text highlight color of the current theme. This is a cover method for getCurrentTheme().getTextHighlightColor().
Returns:
the text highlight color
See Also:

getHighlightedTextColor

public static ColorUIResource getHighlightedTextColor()
Returns the highlighted text color of the current theme. This is a cover method for getCurrentTheme().getHighlightedTextColor().
Returns:
the highlighted text color
See Also:

getWindowBackground

public static ColorUIResource getWindowBackground()
Returns the window background color of the current theme. This is a cover method for getCurrentTheme().getWindowBackground().
Returns:
the window background color
See Also:

getWindowTitleBackground

public static ColorUIResource getWindowTitleBackground()
Returns the window title background color of the current theme. This is a cover method for getCurrentTheme().getWindowTitleBackground().
Returns:
the window title background color
See Also:

getWindowTitleForeground

public static ColorUIResource getWindowTitleForeground()
Returns the window title foreground color of the current theme. This is a cover method for getCurrentTheme().getWindowTitleForeground().
Returns:
the window title foreground color
See Also:

getWindowTitleInactiveBackground

public static ColorUIResource getWindowTitleInactiveBackground()
Returns the window title inactive background color of the current theme. This is a cover method for getCurrentTheme().getWindowTitleInactiveBackground().
Returns:
the window title inactive background color
See Also:

getWindowTitleInactiveForeground

public static ColorUIResource getWindowTitleInactiveForeground()
Returns the window title inactive foreground color of the current theme. This is a cover method for getCurrentTheme().getWindowTitleInactiveForeground().
Returns:
the window title inactive foreground color
See Also:

getMenuBackground

public static ColorUIResource getMenuBackground()
Returns the menu background color of the current theme. This is a cover method for getCurrentTheme().getMenuBackground().
Returns:
the menu background color
See Also:

getMenuForeground

public static ColorUIResource getMenuForeground()
Returns the menu foreground color of the current theme. This is a cover method for getCurrentTheme().getMenuForeground().
Returns:
the menu foreground color
See Also:

getMenuSelectedBackground

public static ColorUIResource getMenuSelectedBackground()
Returns the menu selected background color of the current theme. This is a cover method for getCurrentTheme().getMenuSelectedBackground().
Returns:
the menu selected background color
See Also:

getMenuSelectedForeground

public static ColorUIResource getMenuSelectedForeground()
Returns the menu selected foreground color of the current theme. This is a cover method for getCurrentTheme().getMenuSelectedForeground().
Returns:
the menu selected foreground color
See Also:

getMenuDisabledForeground

public static ColorUIResource getMenuDisabledForeground()
Returns the menu disabled foreground color of the current theme. This is a cover method for getCurrentTheme().getMenuDisabledForeground().
Returns:
the menu disabled foreground color
See Also:

getSeparatorBackground

public static ColorUIResource getSeparatorBackground()
Returns the separator background color of the current theme. This is a cover method for getCurrentTheme().getSeparatorBackground().
Returns:
the separator background color
See Also:

getSeparatorForeground

public static ColorUIResource getSeparatorForeground()
Returns the separator foreground color of the current theme. This is a cover method for getCurrentTheme().getSeparatorForeground().
Returns:
the separator foreground color
See Also:

getAcceleratorForeground

public static ColorUIResource getAcceleratorForeground()
Returns the accelerator foreground color of the current theme. This is a cover method for getCurrentTheme().getAcceleratorForeground().
Returns:
the separator accelerator foreground color
See Also:

getAcceleratorSelectedForeground

public static ColorUIResource getAcceleratorSelectedForeground()
Returns the accelerator selected foreground color of the current theme. This is a cover method for getCurrentTheme().getAcceleratorSelectedForeground().
Returns:
the accelerator selected foreground color
See Also:

getLayoutStyle

public LayoutStyle getLayoutStyle()
Returns a LayoutStyle implementing the Java look and feel design guidelines.
Overrides:
getLayoutStyle in class LookAndFeel
Returns:
LayoutStyle implementing the Java look and feel design guidelines
Since:
1.6
See Also:

© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/javax/swing/plaf/metal/MetalLookAndFeel.html