implements UIDefaults.ActiveValue : UIDefaults « javax.swing « Java by API






implements UIDefaults.ActiveValue

 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;

public class MainClass {
  public static void main(String args[]) {
    final String LABEL_FACTORY = "LabelFactory";
    
    JFrame frame = new JFrame("Active Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    UIManager.put(LABEL_FACTORY, new ActiveLabel());

    final JPanel panel = new JPanel();

    JButton button = new JButton("Get");

    ActionListener actionListener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        JLabel label = (JLabel)UIManager.get(LABEL_FACTORY);
        panel.add(label);
        panel.revalidate();
      }
    };
    button.addActionListener(actionListener);

    frame.add(panel, BorderLayout.CENTER);
    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(200, 200);
    frame.setVisible(true);  }
}

class ActiveLabel implements UIDefaults.ActiveValue {
  private int counter = 0;

  public Object createValue(UIDefaults defaults) {
    JLabel label = new JLabel(""+counter++);
    return label;
  }
}

           
         
  








Related examples in the same category

1.UIDefaults.ProxyLazyValue(String c, Object[] o)
2.UIDefaults: getBoolean(Object key)
3.UIDefaults: getColor(Object key)
4.UIDefaults: getDimension(Object key)
5.UIDefaults: getFont(Object key)
6.UIDefaults: getIcon(Object key)
7.UIDefaults: getInsets(Object key)
8.UIDefaults: getInt(Object key)