UIManager: get(Object key) : UIManager « javax.swing « Java by API






UIManager: get(Object key)

  


import java.awt.BorderLayout;
import java.awt.Container;
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 Main {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Active Example");
    UIManager.put("LabelFactory", 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("LabelFactory");
        panel.add(label);
        panel.revalidate();
      }
    };
    button.addActionListener(actionListener);

    Container contentPane = frame.getContentPane();
    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.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.UIManager.LookAndFeelInfo: getClassName()
2.UIManager.LookAndFeelInfo: getClassName() (2)
3.UIManager.LookAndFeelInfo: getName()
4.UIManager: getBorder(Object key)
5.UIManager: getCrossPlatformLookAndFeelClassName()
6.UIManager: getInstalledLookAndFeels()
7.UIManager: getLookAndFeelDefaults()
8.UIManager: getSystemLookAndFeelClassName()
9.UIManager: put(Object key, Object value)
10.UIManager: setLookAndFeel(String className)