The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > UI Default Values  [3 examples]

e872. Setting a UI Default Value That Is Created at Every Fetch

The UIDefaults table supports values that are created every time they are fetched. Such values are called active values.

For values that are created only once, see e871 Setting a UI Default Value That Is Created When Fetched.

This example declares an active value (a Date) that is created every time it is fetched.

    // Create an active value
    Object activeValue = new UIDefaults.ActiveValue() {
        // This method is called every time the value is fetched.
        // If this method can be called no more than once, it must be synchronized.
        public Object createValue(UIDefaults table) {
            return new Date();
        }
    };
    
    // Add the active value to the UI defaults table
    UIManager.put("key", activeValue);
    
    // Fetch the value twice; this causes the value to be created twice
    Date d1 = (Date)UIManager.get("key");
    Date d2 = (Date)UIManager.get("key");
    boolean b = d1.equals(d2);   // false

 Related Examples
e870. Getting the Default Values for a Look and Feel
e871. Setting a UI Default Value That Is Created When Fetched

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips   


© 2002 Addison-Wesley.