import java.awt.Color;
import javax.swing.colorchooser.ColorSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
import javax.swing.JColorChooser;
...
private final JColorChooser colorChooser = new JColorChooser();
...
ColorSelectionModel model = chooser.getSelectionModel();
model.addChangeListener( new ChangeListener()
{
/**
* what happens when Selected color is changed
*
* @param evt event details
*/
public void stateChanged( ChangeEvent evt )
{
ColorSelectionModel model = ( ColorSelectionModel )evt.getSource();
Color selectedColor = model.getSelectedColor();
if ( selectingForeground )
{
setSelectedForeground ( selectedColor );
}
else
{
setSelectedBackground ( selectedColor );
}
fireStateChanged();
}
});