Java Reference
In-Depth Information
To create the component, you need to install the
ActiveLabel
class with
UIManager.put()
.
Once the class is installed, each call to
get()
the key out of the
UIManager
results in a new
component being created.
UIManager.put(LABEL_FACTORY, new ActiveLabel());
...
JLabel label = (JLabel)UIManager.get(LABEL_FACTORY);
Figure 20-5 shows the component in use. Whenever the button is clicked, the
UIManager.get()
method is called, and the component is added to the screen.
Figure 20-5.
Using active values
Listing 20-6 shows the source for the sample program in Figure 20-5.
Listing 20-6.
Active UIResources
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ActiveSample {
private static final String LABEL_FACTORY = "LabelFactory";
public static void main (String args[]) {
Runnable runner = new Runnable() {
public void run() {
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");