| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public abstract class LookAndFeel extends Object
{@code LookAndFeel}, as the name implies, encapsulates a look and feel. Beyond installing a look and feel most developers never need to interact directly with {@code LookAndFeel}. In general only developers creating a custom look and feel need to concern themselves with this class.
Swing is built upon the foundation that each {@code JComponent} subclass has an implementation of a specific {@code ComponentUI} subclass. The {@code ComponentUI} is often referred to as "the ui", "component ui", or "look and feel delegate". The {@code ComponentUI} subclass is responsible for providing the look and feel specific functionality of the component. For example, {@code JTree} requires an implementation of the {@code ComponentUI} subclass {@code TreeUI}. The implementation of the specific {@code ComponentUI} subclass is provided by the {@code LookAndFeel}. Each {@code JComponent} subclass identifies the {@code ComponentUI} subclass it requires by way of the {@code JComponent} method {@code getUIClassID}.
Each {@code LookAndFeel} implementation must provide an implementation of the appropriate {@code ComponentUI} subclass by specifying a value for each of Swing's ui class ids in the {@code UIDefaults} object returned from {@code getDefaults}. For example, {@code BasicLookAndFeel} uses {@code BasicTreeUI} as the concrete implementation for {@code TreeUI}. This is accomplished by {@code BasicLookAndFeel} providing the key-value pair {@code "TreeUI"-"javax.swing.plaf.basic.BasicTreeUI"}, in the {@code UIDefaults} returned from {@code getDefaults}. Refer to {@link UIDefaults#getUI(JComponent)} for defails on how the implementation of the {@code ComponentUI} subclass is obtained.
When a {@code LookAndFeel} is installed the {@code UIManager} does not check that an entry exists for all ui class ids. As such, random exceptions will occur if the current look and feel has not provided a value for a particular ui class id and an instance of the {@code JComponent} subclass is created.
For primitive values, such as {@code opaque}, the method {@code installProperty} should be invoked. {@code installProperty} only changes the correspoding property if the value has not been changed by the developer.
{@code ComponentUI} implementations should use the various install methods provided by this class as they handle the necessary checking and install the property using the recommended guidelines.
JComponent c; Font font = c.getFont(); if (font == null || (font instanceof UIResource)) { c.setFont(UIManager.getFont("fontKey")); }If the font is {@code null} or a {@code UIResource}, the defaults table is queried with the key {@code fontKey}. All of {@code UIDefault's} get methods throw a {@code NullPointerException} if passed in {@code null}. As such, unless otherwise noted each of the various install methods of {@code LookAndFeel} throw a {@code NullPointerException} if the current value is {@code null} or a {@code UIResource} and the supplied defaults key is {@code null}. In addition, unless otherwise specified all of the {@code install} methods throw a {@code NullPointerException} if a {@code null} component is passed in.
Constructor Summary | |
---|---|
|
Method Summary | |
---|---|
UIDefaults |
Returns the look and feel defaults. |
abstract String |
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 |
Returns the LayoutStyle for this look
and feel.
|
abstract String |
getName() Return a short string that identifies this look and feel, e.g. |
boolean |
Returns if the LookAndFeel returned
RootPaneUI instances support providing
decorations in a JRootPane .
|
void |
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 |
If the underlying platform has a "native" look and feel, and this is an implementation of it, return . |
abstract boolean |
Return if the underlying platform supports and or permits this look and feel. |
static void |
loadKeyBindings(InputMap retMap, Object[] keys) Populates an with the specified bindings. |
static ComponentInputMap |
makeComponentInputMap(JComponent c, Object[] keys) Creates a from keys .
|
static Object |
Creates and returns a that loads an image. |
static InputMap |
makeInputMap(Object[] keys) Creates a from keys .
|
static JTextComponent.KeyBinding[] |
makeKeyBindings(Object[] keyBindingList) Convenience method for building an array of . |
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 |
Uninitializes the look and feel. |
static void |
Convenience method for uninstalling a border. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LookAndFeel()
Method Detail |
---|
public UIDefaults getDefaults()
public abstract String getDescription()
public static Object getDesktopPropertyValue(String systemPropertyName, Object fallbackValue)
Toolkit.getDefaultToolkit().getDesktopProperty()
.
If the value of the specified property is {@code null},
{@code fallbackValue} is returned.
systemPropertyName
- the name of the system desktop property being queriedfallbackValue
- the object to be returned as the value if the system value is nullpublic Icon getDisabledIcon(JComponent component, Icon icon)
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 {@code null} is passed as
icon
this method returns {@code null}.
Some look and feels might not render the disabled {@code Icon}, in which case they will ignore this.
component
- {@code JComponent} that will display the {@code Icon},
may be {@code null}icon
- {@code Icon} to generate the disabled icon frompublic Icon getDisabledSelectedIcon(JComponent component, Icon icon)
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 {@code null} is passed as icon
this
methods returns {@code null}.
Some look and feels might not render the disabled and selected {@code Icon}, in which case they will ignore this.
component
- {@code JComponent} that will display the {@code Icon},
may be {@code null}icon
- {@code Icon} to generate disabled and selected icon frompublic abstract String getID()
public LayoutStyle getLayoutStyle()
LayoutStyle
for this look
and feel. This never returns {@code null}.
You generally don't use the LayoutStyle
from
the look and feel, instead use the LayoutStyle
method getInstance
.
LayoutStyle
for this look and feelpublic abstract String getName()
public boolean getSupportsWindowDecorations()
LookAndFeel
returned
RootPaneUI
instances support providing {@code Window}
decorations in a JRootPane
.
The default implementation returns {@code false}, subclasses that support {@code Window} decorations should override this and return {@code true}.
public void initialize()
public static void installBorder(JComponent c, String defaultBorderName)
c
- component to set the border ondefaultBorderName
- key specifying the borderpublic static void installColors(JComponent c, String defaultBgName, String defaultFgName)
c
- component to set the colors ondefaultBgName
- key for the backgrounddefaultFgName
- key for the foregroundpublic static void installColorsAndFont(JComponent c, String defaultBgName, String defaultFgName, String defaultFontName)
c
- component set to the colors and font ondefaultBgName
- key for the backgrounddefaultFgName
- key for the foregrounddefaultFontName
- key for the fontpublic static void installProperty(JComponent c, String propertyName, Object propertyValue)
c
- target component to set the property onpropertyName
- name of the property to setpropertyValue
- value of the propertypublic abstract boolean isNativeLookAndFeel()
public abstract boolean isSupportedLookAndFeel()
public static void loadKeyBindings(InputMap retMap, Object[] keys)
The following illustrates loading an {@code InputMap} with two {@code key-action} pairs:
LookAndFeel.loadKeyBindings(inputMap, new Object[] { "control X", "cut", "control V", "paste" });
Supplying a {@code null} list of bindings ({@code keys}) does not change {@code retMap} in any way.
Specifying a {@code null} {@code action key} results in removing the {@code keystroke's} entry from the {@code InputMap}. A {@code null} {@code keystroke} is ignored.
retMap
- {@code InputMap} to add the {@code key-action}
pairs tokeys
- bindings to add to {@code retMap}public static ComponentInputMap makeComponentInputMap(JComponent c, Object[] keys)
keys
. This is a convenience method for creating a
new {@code ComponentInputMapUIResource}, invoking {@code
loadKeyBindings(map, keys)}, and returning the {@code
ComponentInputMapUIResource}.
c
- component to create the {@code ComponentInputMapUIResource}
withkeys
- alternating pairs of {@code keystroke-action key}
pairs as described in {@link #loadKeyBindings}public static Object makeIcon(Class baseClass, String gifFile)
This method does not check the arguments in any way. It is strongly recommended that {@code non-null} values are supplied else exceptions may occur when {@code createValue} is invoked on the returned object.
baseClass
- {@code Class} used to load the resourcegifFile
- path to the image to loadpublic static InputMap makeInputMap(Object[] keys)
keys
. This is
a convenience method for creating a new {@code InputMapUIResource},
invoking {@code loadKeyBindings(map, keys)}, and returning the
{@code InputMapUIResource}.
keys
- alternating pairs of {@code keystroke-action key}
pairs as described in {@link #loadKeyBindings}public static JTextComponent.KeyBinding[] makeKeyBindings(Object[] keyBindingList)
This method returns an array of {@code KeyBindings}, one for each
alternating {@code key-action} pair in {@code keyBindingList}.
A {@code key} can either be a {@code String} in the format
specified by the KeyStroke.getKeyStroke
method, or
a {@code KeyStroke}. The {@code action} part of the pair is a
{@code String} that corresponds to the name of the {@code
Action}.
The following example illustrates creating a {@code KeyBinding} array from six alternating {@code key-action} pairs:
JTextComponent.KeyBinding[] multilineBindings = makeKeyBindings( new Object[] { "UP", DefaultEditorKit.upAction, "DOWN", DefaultEditorKit.downAction, "PAGE_UP", DefaultEditorKit.pageUpAction, "PAGE_DOWN", DefaultEditorKit.pageDownAction, "ENTER", DefaultEditorKit.insertBreakAction, "TAB", DefaultEditorKit.insertTabAction });If {@code keyBindingList's} length is odd, the last element is ignored.
Supplying a {@code null} value for either the {@code key} or {@code action} part of the {@code key-action} pair results in creating a {@code KeyBinding} with the corresponding value {@code null}. As other parts of Swing's expect {@code non-null} values in a {@code KeyBinding}, you should avoid supplying {@code null} as either the {@code key} or {@code action} part of the {@code key-action} pair.
keyBindingList
- an array of {@code key-action} pairspublic void provideErrorFeedback(Component component)
JTextField
that has focus. The default implementation beeps. Subclasses
that wish different behavior should override this and provide
the additional feedback.
component
- the Component
the error occurred in,
may be null
indicating the error condition is not directly
associated with a Component
public String toString()
toString
in class Object
public void uninitialize()
Subclasses may choose to free up some resources here.
public static void uninstallBorder(JComponent c)
c
- component to uninstall the border on
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |