The objective is to change the Preview section from this :
To something like this where the Preview area has a border, a solid box in the background and "Hello World" string which changes to the color selected for the Preview.
Started with this sample from java2 which simply shows the JColorChooser.
import java.awt.BorderLayout;
import java.awt.Color;
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 ColorChooserSample {
public static void main(String args[]) {
JFrame f = new JFrame("JColorChooser Sample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = f.getContentPane();
final JButton button = new JButton("Pick to Change Background");
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
Color initialBackground = button.getBackground();
JColorChooser jColorChooser = new JColorChooser();
jColorChooser.setPreviewPanel(null);
Color background = jColorChooser.showDialog(null,
"JColorChooser Sample", initialBackground);
if (background != null) {
button.setBackground(background);
}
}
};
button.addActionListener(actionListener);
content.add(button, BorderLayout.CENTER);
f.setSize(300, 200);
f.setVisible(true);
}
}
Just to see if I can even affect the Preview area, I modified the original code from this :
Color background = JColorChooser.showDialog(null,
"JColorChooser Sample", initialBackground);
To this :
JColorChooser jColorChooser = new JColorChooser();
jColorChooser.setPreviewPanel(null);
Color background = jColorChooser.showDialog(null,
"JColorChooser Sample", initialBackground);
Basically this is to attempt to see if the Preview section could be null (blank) but it had no affect which has me wondering if the setPreviewPanel() is the correct call.
Also, after the code change this Warning appears : The static method showDialog(Component, String, Color) from the type JColorChooser should be accessed in a static way
Questions :
Are there any examples which alter the preview section of the Color Chooser?
Why did the null above not work.
If the Warning indicates that JColorChooser should be accessed in a static way, how would one actually make a setPreviewPanel() call?


There weren't many examples of modifying the
JColorChooserpreview panel. I found four examples. Along with the Javadoc forJColorChooser, I created a working example of a modifiedJColorChooserpreview panel.I modified the original
JFrame/JPanelto change the background color of theJPanel, so it would be easier to see the result.Here's the modified
JColorChooser.Here I changed the background color of the preview
JPanelto yellow.Which then changes the background color of the main
JPanelto yellow.Here's the code. I separated the code into bite-sized methods and classes, so I could concentrate on one part of the GUI data a time.