DesktopProperty.javaAPI DocJava SE 5 API8358Fri Aug 26 14:54:48 BST


public class DesktopProperty extends Object implements UIDefaults$ActiveValue
Wrapper for a value from the desktop. The value is lazily looked up, and can be accessed using the UIManager.ActiveValue method createValue. If the underlying desktop property changes this will force the UIs to update all known Frames. You can invoke invalidate to force the value to be fetched again.
@(#) 1.9 05/03/25

Fields Summary
private static boolean
Indicates if an updateUI call is pending.
private static ReferenceQueue
ReferenceQueue of unreferenced WeakPCLs.
private WeakPCL
PropertyChangeListener attached to the Toolkit.
private String
Key used to lookup value from desktop.
private Object
Value to return.
private Object
Fallback value in case we get null from desktop.
private Toolkit
Constructors Summary
public DesktopProperty(String key, Object fallback, Toolkit toolkit)
Creates a DesktopProperty.

key Key used in looking up desktop value.
fallback Value used if desktop property is null.
toolkit Toolkit used to fetch property from, can be null in which default will be used.

        this.key = key;
        this.fallback = fallback;
        this.toolkit = toolkit;
        // The only sure fire way to clear our references is to create a
        // Thread and wait for a reference to be added to the queue.
        // Because it is so rare that you will actually change the look
        // and feel, this stepped is forgoed and a middle ground of
        // flushing references from the constructor is instead done.
        // The implication is that once one DesktopProperty is created
        // there will most likely be n (number of DesktopProperties created
        // by the LookAndFeel) WeakPCLs around, but this number will not
        // grow past n.
Methods Summary
protected java.lang.ObjectconfigureValue(java.lang.Object value)
Configures the value as appropriate for a defaults property in the UIDefaults table.

        if (value != null) {
            if (value instanceof Color) {
                return new ColorUIResource((Color)value);
            else if (value instanceof Font) {
                return new FontUIResource((Font)value);
            else if (value instanceof UIDefaults.LazyValue) {
                value = ((UIDefaults.LazyValue)value).createValue(null);
            else if (value instanceof UIDefaults.ActiveValue) {
                value = ((UIDefaults.ActiveValue)value).createValue(null);
        return value;
public java.lang.ObjectcreateValue(javax.swing.UIDefaults table)
UIManager.LazyValue method, returns the value from the desktop or the fallback value if the desktop value is null.

        if (value == null) {
            value = configureValue(getValueFromDesktop());
            if (value == null) {
                value = configureValue(getDefaultValue());
        return value;
static voidflushUnreferencedProperties()
Cleans up any lingering state held by unrefeernced DesktopProperties.

        queue = new ReferenceQueue();
        WeakPCL pcl;

        while ((pcl = (WeakPCL)queue.poll()) != null) {
protected java.lang.ObjectgetDefaultValue()
Returns the value to use if the desktop property is null.

        return fallback;
protected java.lang.StringgetKey()
Returns the key used to lookup the desktop properties value.

        return key;
protected java.lang.ObjectgetValueFromDesktop()
Returns the value from the desktop.

        if (this.toolkit == null) {
            this.toolkit = Toolkit.getDefaultToolkit();
        Object value = toolkit.getDesktopProperty(getKey());
        pcl = new WeakPCL(this, toolkit, getKey(), UIManager.getLookAndFeel());
        toolkit.addPropertyChangeListener(getKey(), pcl);
        return value;
public voidinvalidate()
Invalides the current value so that the next invocation of createValue will ask for the property again.

        if (pcl != null) {
            toolkit.removePropertyChangeListener(getKey(), pcl);
            toolkit = null;
            pcl = null;
            value = null;
private static synchronized booleanisUpdatePending()
Returns true if a UI update is pending.

	return updatePending;
private static synchronized voidsetUpdatePending(boolean update)
Sets whether or not an updateUI call is pending.

	updatePending = update;
private static voidupdateAllUIs()
Updates the UIs of all the known Frames.

	// Check if the current UI is WindowsLookAndfeel and flush the XP style map.
	// Note: Change the package test if this class is moved to a different package.
	Class uiClass = UIManager.getLookAndFeel().getClass();
 	if (uiClass.getPackage().equals(DesktopProperty.class.getPackage())) {
        Frame appFrames[] = Frame.getFrames();
	for (int j=0; j < appFrames.length; j++) {
protected voidupdateUI()
Requests that all components in the GUI hierarchy be updated to reflect dynamic changes in this look&feel. This update occurs by uninstalling and re-installing the UI objects. Requests are batched and collapsed into a single update pass because often many desktop properties will change at once.

	if (!isUpdatePending()) {
            Runnable uiUpdater = new Runnable() {
                public void run() {
private static voidupdateWindowUI(java.awt.Window window)
Updates the UI of the passed in window and all its children.

	Window ownedWins[] = window.getOwnedWindows();
	for (int i=0; i < ownedWins.length; i++) {