JColorChooser's preview panel will not go away.

In my app i just tried adding a jcolorchooser but cant get the preview panel to go away, so i wrote this code that shows exactly what im doing. This code works, but the preview panel is still there.

publicclass Colorextends javax.swing.JFrameimplements java.awt.event.ActionListener

{

private javax.swing.JColorChooser _c;

private javax.swing.JButton a;

public Color()

{

_c =new javax.swing.JColorChooser();

_c.setPreviewPanel(new javax.swing.JPanel());

a =new javax.swing.JButton("change bg");

a.addActionListener(this);

this.add(a);

this.setVisible(true);

this.setSize(300, 300);

this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

}

publicvoid actionPerformed(java.awt.event.ActionEvent e)

{ a.setBackground(_c.showDialog(null,"colors", this.getBackground()));}

publicstaticvoid main(String[] args)

{new Color();}

}

[1822 byte] By [foolfoolza] at [2007-11-27 10:18:12]
# 1

showDialog() is a static method so it does not use fhe color chooser that you just created. It will create its own JColorChooser.

If you want to use a custom color chooser then you need to add the color to your own panel.

Read the JColorChooser API and follow the link to the Swing tutorial on "How to Use Color Choosers". The ColorChooserDemo2 shows you how to do what you want.

camickra at 2007-7-28 15:56:07 > top of Java-index,Desktop,Core GUI APIs...
# 2

Use createDialog function of JColorChooser instead of showDialog, and pass you JColorChooser object to this function.

Rodney_McKaya at 2007-7-28 15:56:07 > top of Java-index,Desktop,Core GUI APIs...