Methods Summary |
---|
public javax.swing.UIDefaults | getDefaults()Returns the look and feel defaults. While this method is public,
it should only be invoked by the {@code UIManager} when the
look and feel is set as the current look and feel and after
{@code initialize} has been invoked.
return null;
|
public abstract java.lang.String | getDescription()Return a one line description of this look and feel implementation,
e.g. "The CDE/Motif Look and Feel". This string is intended for
the user, e.g. in the title of a window or in a ToolTip message.
|
public static java.lang.Object | getDesktopPropertyValue(java.lang.String systemPropertyName, java.lang.Object fallbackValue)Returns the value of the specified system desktop property by
invoking Toolkit.getDefaultToolkit().getDesktopProperty() .
If the value of the specified property is {@code null},
{@code fallbackValue} is returned.
Object value = Toolkit.getDefaultToolkit().getDesktopProperty(systemPropertyName);
if (value == null) {
return fallbackValue;
} else if (value instanceof Color) {
return new ColorUIResource((Color)value);
} else if (value instanceof Font) {
return new FontUIResource((Font)value);
}
return value;
|
public javax.swing.Icon | getDisabledIcon(javax.swing.JComponent component, javax.swing.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 {@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.
if (icon instanceof ImageIcon) {
return new ImageIconUIResource(GrayFilter.
createDisabledImage(((ImageIcon)icon).getImage()));
}
return null;
|
public javax.swing.Icon | getDisabledSelectedIcon(javax.swing.JComponent component, javax.swing.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 {@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.
return getDisabledIcon(component, icon);
|
public abstract java.lang.String | getID()Return a string that identifies this look and feel. This string
will be used by applications/services that want to recognize
well known look and feel implementations. Presently
the well known names are "Motif", "Windows", "Mac", "Metal". Note
that a LookAndFeel derived from a well known superclass
that doesn't make any fundamental changes to the look or feel
shouldn't override this method.
|
public javax.swing.LayoutStyle | getLayoutStyle()Returns the 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 .
return DefaultLayoutStyle.getInstance();
|
public abstract java.lang.String | getName()Return a short string that identifies this look and feel, e.g.
"CDE/Motif". This string should be appropriate for a menu item.
Distinct look and feels should have different names, e.g.
a subclass of MotifLookAndFeel that changes the way a few components
are rendered should be called "CDE/Motif My Way"; something
that would be useful to a user trying to select a L&F from a list
of names.
|
public boolean | getSupportsWindowDecorations()Returns {@code true} if the 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}.
return false;
|
public void | initialize()Initializes the look and feel. While this method is public,
it should only be invoked by the {@code UIManager} when a
look and feel is installed as the current look and feel. This
method is invoked before the {@code UIManager} invokes
{@code getDefaults}. This method is intended to perform any
initialization for the look and feel. Subclasses
should do any one-time setup they need here, rather than
in a static initializer, because look and feel class objects
may be loaded just to discover that {@code isSupportedLookAndFeel()}
returns {@code false}.
|
public static void | installBorder(javax.swing.JComponent c, java.lang.String defaultBorderName)Convenience method for setting a component's border property with
a value from the defaults. The border is only set if the border is
{@code null} or an instance of {@code UIResource}.
Border b = c.getBorder();
if (b == null || b instanceof UIResource) {
c.setBorder(UIManager.getBorder(defaultBorderName));
}
|
public static void | installColors(javax.swing.JComponent c, java.lang.String defaultBgName, java.lang.String defaultFgName)Convenience method for setting a component's foreground
and background color properties with values from the
defaults. The properties are only set if the current
value is either {@code null} or a {@code UIResource}.
Color bg = c.getBackground();
if (bg == null || bg instanceof UIResource) {
c.setBackground(UIManager.getColor(defaultBgName));
}
Color fg = c.getForeground();
if (fg == null || fg instanceof UIResource) {
c.setForeground(UIManager.getColor(defaultFgName));
}
|
public static void | installColorsAndFont(javax.swing.JComponent c, java.lang.String defaultBgName, java.lang.String defaultFgName, java.lang.String defaultFontName)Convenience method for setting a component's foreground,
background and font properties with values from the
defaults. The properties are only set if the current
value is either {@code null} or a {@code UIResource}.
Font f = c.getFont();
if (f == null || f instanceof UIResource) {
c.setFont(UIManager.getFont(defaultFontName));
}
installColors(c, defaultBgName, defaultFgName);
|
public static void | installProperty(javax.swing.JComponent c, java.lang.String propertyName, java.lang.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. This method is intended to be used by
ui delegate instances that need to specify a default value for a
property of primitive type (boolean, int, ..), but do not wish
to override a value set by the client. Since primitive property
values cannot be wrapped with the {@code UIResource} marker, this method
uses private state to determine whether the property has been set
by the client.
// this is a special case because the JPasswordField's ancestor heirarchy
// includes a class outside of javax.swing, thus we cannot call setUIProperty
// directly.
if (c instanceof JPasswordField) {
if (!((JPasswordField)c).customSetUIProperty(propertyName, propertyValue)) {
c.setUIProperty(propertyName, propertyValue);
}
} else {
c.setUIProperty(propertyName, propertyValue);
}
|
public abstract boolean | isNativeLookAndFeel()If the underlying platform has a "native" look and feel, and
this is an implementation of it, return {@code true}. For
example, when the underlying platform is Solaris running CDE
a CDE/Motif look and feel implementation would return {@code
true}.
|
public abstract boolean | isSupportedLookAndFeel()Return {@code true} if the underlying platform supports and or permits
this look and feel. This method returns {@code false} if the look
and feel depends on special resources or legal agreements that
aren't defined for the current platform.
|
public static void | loadKeyBindings(javax.swing.InputMap retMap, java.lang.Object[] keys)Populates an {@code InputMap} with the specified bindings.
The bindings are supplied as a list of alternating
{@code keystroke-action key} pairs. The {@code keystroke} is either
an instance of {@code KeyStroke}, or a {@code String}
that identifies the {@code KeyStroke} for the binding. Refer
to {@code KeyStroke.getKeyStroke(String)} for the specific
format. The {@code action key} part of the pair is the key
registered in the {@code InputMap} for the {@code KeyStroke}.
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.
if (keys != null) {
for (int counter = 0, maxCounter = keys.length;
counter < maxCounter; counter++) {
Object keyStrokeO = keys[counter++];
KeyStroke ks = (keyStrokeO instanceof KeyStroke) ?
(KeyStroke)keyStrokeO :
KeyStroke.getKeyStroke((String)keyStrokeO);
retMap.put(ks, keys[counter]);
}
}
|
public static javax.swing.ComponentInputMap | makeComponentInputMap(javax.swing.JComponent c, java.lang.Object[] keys)Creates a {@code ComponentInputMapUIResource} from
keys . This is a convenience method for creating a
new {@code ComponentInputMapUIResource}, invoking {@code
loadKeyBindings(map, keys)}, and returning the {@code
ComponentInputMapUIResource}.
ComponentInputMap retMap = new ComponentInputMapUIResource(c);
loadKeyBindings(retMap, keys);
return retMap;
|
public static java.lang.Object | makeIcon(java.lang.Class baseClass, java.lang.String gifFile)Creates and returns a {@code UIDefault.LazyValue} that loads an
image. The returned value is an implementation of {@code
UIDefaults.LazyValue}. When {@code createValue} is invoked on
the returned object, the image is loaded. If the image is {@code
non-null}, it is then wrapped in an {@code Icon} that implements {@code
UIResource}. The image is loaded using {@code
Class.getResourceAsStream(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.
return SwingUtilities2.makeIcon(baseClass, baseClass, gifFile);
|
public static javax.swing.InputMap | makeInputMap(java.lang.Object[] keys)Creates a {@code InputMapUIResource} from keys . This is
a convenience method for creating a new {@code InputMapUIResource},
invoking {@code loadKeyBindings(map, keys)}, and returning the
{@code InputMapUIResource}.
InputMap retMap = new InputMapUIResource();
loadKeyBindings(retMap, keys);
return retMap;
|
public static javax.swing.text.JTextComponent$KeyBinding[] | makeKeyBindings(java.lang.Object[] keyBindingList)Convenience method for building an array of {@code
KeyBindings}. While this method is not deprecated, developers
should instead use {@code ActionMap} and {@code InputMap} for
supplying key bindings.
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.
JTextComponent.KeyBinding[] rv = new JTextComponent.KeyBinding[keyBindingList.length / 2];
for(int i = 0; i < keyBindingList.length; i += 2) {
KeyStroke keystroke = (keyBindingList[i] instanceof KeyStroke)
? (KeyStroke)keyBindingList[i]
: KeyStroke.getKeyStroke((String)keyBindingList[i]);
String action = (String)keyBindingList[i+1];
rv[i / 2] = new JTextComponent.KeyBinding(keystroke, action);
}
return rv;
|
public void | provideErrorFeedback(java.awt.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.
Toolkit toolkit = null;
if (component != null) {
toolkit = component.getToolkit();
} else {
toolkit = Toolkit.getDefaultToolkit();
}
toolkit.beep();
|
public java.lang.String | toString()Returns a string that displays and identifies this
object's properties.
return "[" + getDescription() + " - " + getClass().getName() + "]";
|
public void | uninitialize()Uninitializes the look and feel. While this method is public,
it should only be invoked by the {@code UIManager} when
the look and feel is uninstalled. For example,
{@code UIManager.setLookAndFeel} invokes this when the look and
feel is changed.
Subclasses may choose to free up some resources here.
|
public static void | uninstallBorder(javax.swing.JComponent c)Convenience method for uninstalling a border. If the border of
the component is a {@code UIResource}, it is set to {@code
null}.
if (c.getBorder() instanceof UIResource) {
c.setBorder(null);
}
|