A quick test of the JColorChooser dialog : Color Chooser « Swing JFC « Java






A quick test of the JColorChooser dialog

A quick test of the JColorChooser dialog
   
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;

public class ColorPicker extends JFrame {

  public ColorPicker() {
    super("JColorChooser Test Frame");
    setSize(200, 100);
    final Container contentPane = getContentPane();
    final JButton go = new JButton("Show JColorChooser");
    go.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        Color c;
        c = JColorChooser.showDialog(((Component) e.getSource())
            .getParent(), "Demo", Color.blue);
        contentPane.setBackground(c);
      }
    });
    contentPane.add(go, BorderLayout.SOUTH);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }

  public static void main(String args[]) {
    ColorPicker cp = new ColorPicker();
    cp.setVisible(true);
  }
}

           
         
    
    
  








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.ColorChooser Sample 1ColorChooser Sample 1
4.Color Chooser DemoColor Chooser Demo
5.System Color ChooserSystem Color Chooser
6.JColorChooser demoJColorChooser demo
7.ColorChooser Demo 2ColorChooser Demo 2
8.Swing ColorChooser DemoSwing ColorChooser Demo
9.Setting the Order of the Color Chooser Panel Tabs in a JColorChooser Dialog
10.Removing a Color Chooser Panel from a JColorChooser Dialog
11.Preview pane simply displays the currently selected color.
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