Java Reference
In-Depth Information
The specifics of the findColorLabel(Object label) and findColorPosition(Color newColor)
methods are shown in the complete source in Listing 9-11, coming up shortly.
If you don't use the showDialog() means of showing the chooser pop-up window, once the
chooser panel has been defined, and you've created a chooser panel, it can be placed within a
JColorChooser with addChooserPanel() .
AbstractColorChooserPanel newChooser = new SystemColorChooserPanel();
colorChooser.addChooserPanel(newChooser);
After showing the JColorChooser and picking the appropriate tab, your new chooser will
be available for use, as shown in Figure 9-24.
Figure 9-24. After adding the new SystemColor chooser panel
The complete source for the SystemColorChooserPanel is shown in Listing 9-11. The program
should use the ComboBoxModel to store the labels and colors arrays of the example in one data
model. However, the complexities of using the MVC capabilities of the JComboBox will be saved
for Chapter 13. Feel free to change the example in order to use the appropriate data model for
the JComboBox or some of the other Collections API classes available.
Listing 9-11. Custom AbstractColorChooserPanel
import javax.swing.*;
import javax.swing.colorchooser.*;
import java.awt.*;
import java.awt.event.*;
public class SystemColorChooserPanel
extends AbstractColorChooserPanel
implements ItemListener {
 
Search WWH ::




Custom Search