javajcolorchooser

Setting Selected Color of JColorChooser


IS it possible to set the selected color of the JColorChooser?

I tried

_ColorChooser_Color.setColor(color);

but it doesn't work. Meaning, it compiles and runs, but doesnt change the actual selection of the component.

I am now trying to do something like this

 _ColorChooser_Color.setSelectionModel(new ColorSelectionModel().setSelectedColor(color));

But this is giving me an error - ColorSelectionModel is abstract; cannot be instantiated


Solution

  • colorSelector.getSelectionModel().setSelectedColor(newColor)
    

    Doc: http://docs.oracle.com/javase/8/docs/api/javax/swing/colorchooser/ColorSelectionModel.html