Spec-Zone.ru › OpenJDK 27

Class BasicLookAndFeel

java.lang.Object
javax.swing.LookAndFeel
javax.swing.plaf.basic.BasicLookAndFeel
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MetalLookAndFeel, SynthLookAndFeel
public abstract class BasicLookAndFeel extends LookAndFeel implements Serializable
A base class to use in creating a look and feel for Swing.

Each of the ComponentUIs provided by BasicLookAndFeel 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.

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.

Constructor Summary

BasicLookAndFeel()
Modifier Constructor Description
protected
Constructor for subclasses to call.

Method Summary

Modifier and Type Method Description
protected Action createAudioAction(Object key)
Creates and returns an Action used to play a sound.
protected ActionMap getAudioActionMap()
Returns an ActionMap containing the audio actions for this look and feel.
UIDefaults getDefaults()
Returns the look and feel defaults.
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 the basic look and feel.
protected void initSystemColorDefaults(UIDefaults table)
Populates table with system colors.
protected void loadSystemColors(UIDefaults table, String[] systemColors, boolean useNative)
Populates table with the name-color pairs in systemColors.
protected void playSound(Action audioAction)
If necessary, invokes actionPerformed on audioAction to play a sound.

Methods declared in class LookAndFeel

getDescription, getDesktopPropertyValue, getDisabledIcon, getDisabledSelectedIcon, getID, getLayoutStyle, getName, getSupportsWindowDecorations, initialize, installBorder, installColors, installColorsAndFont, installProperty, isNativeLookAndFeel, isSupportedLookAndFeel, loadKeyBindings, makeComponentInputMap, makeIcon, makeInputMap, makeKeyBindings, provideErrorFeedback, toString, uninitialize, uninstallBorder
Modifier and Type Method Description
abstract String getDescription()
Return a one line description of this look and feel implementation, e.g.
static Object getDesktopPropertyValue(String systemPropertyName, Object fallbackValue)
Returns the value of the specified system desktop property by invoking Toolkit.getDefaultToolkit().getDesktopProperty().
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.
abstract String getID()
Return a string that identifies this look and feel.
LayoutStyle getLayoutStyle()
Returns the LayoutStyle for this look and feel.
abstract String getName()
Return a short string that identifies this look and feel, e.g.
boolean getSupportsWindowDecorations()
Returns true if the LookAndFeel returned RootPaneUI instances support providing Window decorations in a JRootPane.
void initialize()
Initializes the look and feel.
static void installBorder(JComponent c, String defaultBorderName)
Convenience method for setting a component's border property with a value from the defaults.
static void installColors(JComponent c, String defaultBgName, String defaultFgName)
Convenience method for setting a component's foreground and background color properties with values from the defaults.
static void installColorsAndFont(JComponent c, String defaultBgName, String defaultFgName, String defaultFontName)
Convenience method for setting a component's foreground, background and font properties with values from the defaults.
static void installProperty(JComponent c, String propertyName, Object propertyValue)
Convenience method for installing a property with the specified name and value on a component if that property has not already been set by the developer.
abstract boolean isNativeLookAndFeel()
If the underlying platform has a "native" look and feel, and this is an implementation of it, return true.
abstract boolean isSupportedLookAndFeel()
Return true if the underlying platform supports and or permits this look and feel.
static void loadKeyBindings(InputMap retMap, Object[] keys)
Populates an InputMap with the specified bindings.
static ComponentInputMap makeComponentInputMap(JComponent c, Object[] keys)
Creates a ComponentInputMapUIResource from keys.
static Object makeIcon(Class<?> baseClass, String gifFile)
Creates and returns a UIDefault.LazyValue that loads an image.
static InputMap makeInputMap(Object[] keys)
Creates an InputMapUIResource from keys.
static JTextComponent.KeyBinding[] makeKeyBindings(Object[] keyBindingList)
Convenience method for building an array of KeyBindings.
void provideErrorFeedback(Component component)
Invoked when the user attempts an invalid operation, such as pasting into an uneditable JTextField that has focus.
String toString()
Returns a string that displays and identifies this object's properties.
void uninitialize()
Uninitializes the look and feel.
static void uninstallBorder(JComponent c)
Convenience method for uninstalling a border.

Methods declared in class Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Modifier and Type Method Description
protected Object clone()
Creates and returns a copy of this object.
boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.
protected void finalize()
Deprecated, for removal: This API element is subject to removal in a future version.
Finalization is deprecated and subject to removal in a future release.
final Class<?> getClass()
Returns the runtime class of this Object.
int hashCode()
Returns a hash code value for this object.
final void notify()
Wakes up a single thread that is waiting on this object's monitor.
final void notifyAll()
Wakes up all threads that are waiting on this object's monitor.
final void wait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
final void wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
final void wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

Constructor Details

BasicLookAndFeel

protected BasicLookAndFeel()
Constructor for subclasses to call.

Method Details

getDefaults

public UIDefaults getDefaults()
Returns the look and feel defaults. The returned UIDefaults is populated by invoking, in order, initClassDefaults, initSystemColorDefaults and initComponentDefaults.

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 LookAndFeel
Returns:
the look and feel defaults
See Also:
  • initClassDefaults(UIDefaults)
  • initSystemColorDefaults(UIDefaults)
  • initComponentDefaults(UIDefaults)

initClassDefaults

protected void initClassDefaults(UIDefaults table)
Populates table with mappings from uiClassID to the fully qualified name of the ui class. The value for a particular uiClassID is "javax.swing.plaf.basic.Basic + uiClassID". For example, the value for the uiClassID TreeUI is "javax.swing.plaf.basic.BasicTreeUI".
Parameters:
table - the UIDefaults instance the entries are added to
Throws:
NullPointerException - if table is null
See Also:
  • LookAndFeel
  • getDefaults()

initSystemColorDefaults

protected void initSystemColorDefaults(UIDefaults table)
Populates table with system colors. This creates an array of name-color pairs and invokes loadSystemColors.

The name is a String that corresponds to the name of one of the static SystemColor fields in the SystemColor class. A name-color pair is created for every such SystemColor field.

The color corresponds to a hex String as understood by Color.decode. For example, one of the name-color pairs is "desktop"-"#005C5C". This corresponds to the SystemColor field desktop, with a color value of new Color(0x005C5C).

The following shows two of the name-color pairs:

  String[] nameColorPairs = new String[] {
         "desktop", "#005C5C",
   "activeCaption", "#000080" };
  loadSystemColors(table, nameColorPairs, isNativeLookAndFeel());
As previously stated, this invokes loadSystemColors with the supplied table and name-color pair array. The last argument to loadSystemColors indicates whether the value of the field in SystemColor should be used. This method passes the value of isNativeLookAndFeel() as the last argument to loadSystemColors.
Parameters:
table - the UIDefaults object the values are added to
Throws:
NullPointerException - if table is null
See Also:
  • SystemColor
  • getDefaults()
  • loadSystemColors(UIDefaults, String[], boolean)

loadSystemColors

protected void loadSystemColors(UIDefaults table, String[] systemColors, boolean useNative)
Populates table with the name-color pairs in systemColors. Refer to initSystemColorDefaults(UIDefaults) for details on the format of systemColors.

An entry is added to table for each of the name-color pairs in systemColors. The entry key is the name of the name-color pair.

The value of the entry corresponds to the color of the name-color pair. The value of the entry is calculated in one of two ways. With either approach the value is always a ColorUIResource.

If useNative is false, the color is created by using Color.decode to convert the String into a Color. If decode can not convert the String into a Color ( NumberFormatException is thrown) then a ColorUIResource of black is used.

If useNative is true, the color is the value of the field in SystemColor with the same name as the name of the name-color pair. If the field is not valid, a ColorUIResource of black is used.

Parameters:
table - the UIDefaults object the values are added to
systemColors - array of name-color pairs as described in initSystemColorDefaults(UIDefaults)
useNative - whether the color is obtained from SystemColor or Color.decode
Throws:
NullPointerException - if systemColors is null; or systemColors is not empty, and table is null; or one of the names of the name-color pairs is null; or useNative is false and one of the colors of the name-color pairs is null
ArrayIndexOutOfBoundsException - if useNative is false and systemColors.length is odd
See Also:
  • initSystemColorDefaults(javax.swing.UIDefaults)
  • SystemColor
  • Color.decode(String)

initComponentDefaults

protected void initComponentDefaults(UIDefaults table)
Populates table with the defaults for the basic look and feel.
Parameters:
table - the UIDefaults to add the values to
Throws:
NullPointerException - if table is null

getAudioActionMap

protected ActionMap getAudioActionMap()
Returns an ActionMap containing the audio actions for this look and feel.

The returned ActionMap contains Actions that embody the ability to render an auditory cue. These auditory cues map onto user and system activities that may be useful for an end user to know about (such as a dialog box appearing).

At the appropriate time, the ComponentUI is responsible for obtaining an Action out of the ActionMap and passing it to playSound.

This method first looks up the ActionMap from the defaults using the key "AuditoryCues.actionMap".

If the value is non-null, it is returned. If the value of the default "AuditoryCues.actionMap" is null and the value of the default "AuditoryCues.cueList" is non-null, an ActionMapUIResource is created and populated. Population is done by iterating over each of the elements of the "AuditoryCues.cueList" array, and invoking createAudioAction() to create an Action for each element. The resulting Action is placed in the ActionMapUIResource, using the array element as the key. For example, if the "AuditoryCues.cueList" array contains a single-element, "audioKey", the ActionMapUIResource is created, then populated by way of actionMap.put(cueList[0], createAudioAction(cueList[0])).

If the value of the default "AuditoryCues.actionMap" is null and the value of the default "AuditoryCues.cueList" is null, an empty ActionMapUIResource is created.

Returns:
an ActionMap containing Actions responsible for playing auditory cues
Throws:
ClassCastException - if the value of the default "AuditoryCues.actionMap" is not an ActionMap, or the value of the default "AuditoryCues.cueList" is not an Object[]
Since:
1.4
See Also:
  • createAudioAction(Object)
  • playSound(Action)

createAudioAction

protected Action createAudioAction(Object key)
Creates and returns an Action used to play a sound.

If key is non-null, an Action is created using the value from the defaults with key key. The value identifies the sound resource to load when actionPerformed is invoked on the Action. The sound resource is loaded into a byte[] by way of getClass().getResourceAsStream().

Parameters:
key - the key identifying the audio action
Returns:
an Action used to play the source, or null if key is null
Since:
1.4
See Also:
  • playSound(Action)

playSound

protected void playSound(Action audioAction)
If necessary, invokes actionPerformed on audioAction to play a sound. The actionPerformed method is invoked if the value of the "AuditoryCues.playList" default is a non-null Object[] containing a String entry equal to the name of the audioAction.
Parameters:
audioAction - an Action that knows how to render the audio associated with the system or user activity that is occurring; a value of null, is ignored
Throws:
ClassCastException - if audioAction is non-null and the value of the default "AuditoryCues.playList" is not an Object[]
Since:
1.4

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2026, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

© 1993, 2025, 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.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API