Java Reference
In-Depth Information
public Icon getSmallDisplayIcon() {
return new DiamondIcon(Color.BLUE);
}
public Icon getLargeDisplayIcon() {
return new DiamondIcon(Color.GREEN);
}
protected void buildChooser() {
comboBox = new JComboBox(labels);
comboBox.addItemListener(this);
add(comboBox);
}
public void updateChooser() {
Color color = getColorFromModel();
setColor(color);
}
}
Listing 9-12 demonstrates the use of the new chooser panel. It's a slightly modified version
of the CreateColorSamplePopup program shown earlier in Listing 9-10. You can uncomment the
setChooserPanels() statement and comment out the addChooserPanel() call to go from adding
one panel (as in Figure 9-23) to replacing all of them (as in Figure 9-24).
Listing 9-12. Having Custom Panels in a JColorChooser
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.colorchooser.*;
public class CustomPanelPopup {
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("JColorChooser Custom Panel Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton("Pick to Change Background");
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
Color initialBackground = button.getBackground();
Search WWH ::




Custom Search