Preview pane simply displays the currently selected color. : Color Chooser « Swing JFC « Java






Preview pane simply displays the currently selected color.

   

class MyPreviewPane extends JLabel{
  Color curColor;
  public MyPreviewPane(JColorChooser chooser) {
    curColor = chooser.getColor();
    ColorSelectionModel model = chooser.getSelectionModel();
    model.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        ColorSelectionModel model = (ColorSelectionModel) evt.getSource();
        curColor = model.getSelectedColor();
      }
    });
    setPreferredSize(new Dimension(50, 50));
  }
  public void paint(Graphics g) {
    g.setColor(curColor);
    g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
  }
}

   
    
    
  








Related examples in the same category

1.JColorChooser dialog with a custom preview pane.JColorChooser dialog with a custom preview pane.
2.JColorChooser dialog with the custom GrayScalePanel picker tab.JColorChooser dialog with the custom GrayScalePanel picker tab.
3.A quick test of the JColorChooser dialogA quick test of the JColorChooser dialog
4.ColorChooser Sample 1ColorChooser Sample 1
5.Color Chooser DemoColor Chooser Demo
6.System Color ChooserSystem Color Chooser
7.JColorChooser demoJColorChooser demo
8.ColorChooser Demo 2ColorChooser Demo 2
9.Swing ColorChooser DemoSwing ColorChooser Demo
10.Setting the Order of the Color Chooser Panel Tabs in a JColorChooser Dialog
11.Removing a Color Chooser Panel from a JColorChooser Dialog
12.Retrieving the Color Chooser Panels in a JColorChooser Dialog
13.Customizing the Preview Panel of a JColorChooser Dialog
14.Getting and Setting the Selected Color in a JColorChooser Dialog
15.Creating a JColorChooser Dialog
16.Listening for Changes to the Selected Color in a JColorChooser Dialog
17.Listening for OK and Cancel Events in a JColorChooser Dialog
18.Removing the Preview Panel from a JColorChooser Dialog
19.Adding a Custom Color Chooser Panel to a JColorChooser Dialog
20.extends AbstractColorChooserPanelextends AbstractColorChooserPanel
21.Choose foreground or background color
22.A panel with buttons to pop up three types of color choosers