Java Reference
In-Depth Information
Figure 9-23.
Replacing all panels with the new SystemColor chooser panel
The first method to define is
public String getDisplayName()
. This method returns a text
label to display on the tab when multiple chooser panels are available. If there's only one chooser
panel, this name isn't shown.
public String getDisplayName() {
return "SystemColor";
}
The return values for the two
Icon
methods do nothing with the system look and feel types.
You can return
null
from them or return an
Icon
to check that nothing has been done with
them. A custom
ColorChooserUI
could use the two
Icon
methods somewhere, possibly for the
icon on a chooser panel tab.
public Icon getSmallDisplayIcon() {
return new DiamondIcon(Color.BLUE);
}
public Icon getLargeDisplayIcon() {
return new DiamondIcon(Color.GREEN);
}
The
protected void buildChooser()
method is called by the
installChooserPanel()
method
of
AbstractColorChooserPanel
when the panel is added to the chooser. You use this method to
add the necessary components to the container. In the sample
SystemColorChooserPanel
chooser, this involves creating the
JComboBox
and adding it to the panel. Because
AbstractColorChooserPanel
is a
JPanel
subclass, you can just
add()
the combo box. The combo
box must be filled with options and an event handler installed for when the user selects the
component. The specifics of the event handling are described after the following block of
source code.
protected void buildChooser() {
comboBox = new JComboBox(labels);
comboBox.addItemListener(this);
add(comboBox);
}