import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ColorPicker extends JFrame { public ColorPicker() { super("JColorChooser Test Frame"); final JButton go = new JButton("Show JColorChooser"); go.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Color c; //Show a color chooser dialog with the preselected color blue. c = JColorChooser.showDialog( ((Component)e.getSource()).getParent(), "Demo", Color.blue); //When returning from the dialog the go button will get //the selected color. go.setBackground(c); } }); getContentPane().add(go); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(200, 100); setVisible(true); } public static void main(String args[]) { new ColorPicker(); } }