Example usage for javax.swing.colorchooser ColorSelectionModel setSelectedColor

List of usage examples for javax.swing.colorchooser ColorSelectionModel setSelectedColor

Introduction

In this page you can find the example usage for javax.swing.colorchooser ColorSelectionModel setSelectedColor.

Prototype

void setSelectedColor(Color color);

Source Link

Document

Sets the selected color to color.

Usage

From source file:SystemColorChooserPanel.java

public void itemStateChanged(ItemEvent itemEvent) {
    int state = itemEvent.getStateChange();
    if (state == ItemEvent.SELECTED) {
        int position = findColorLabel(itemEvent.getItem());

        if ((position != NOT_FOUND) && (position != labels.length - 1)) {
            ColorSelectionModel selectionModel = getColorSelectionModel();
            selectionModel.setSelectedColor(colors[position]);
        }/*from   w  ww. j  ava 2s  .  c o m*/
    }
}

From source file:MainClass.java

public void itemStateChanged(ItemEvent itemEvent) {
    int state = itemEvent.getStateChange();
    if (state == ItemEvent.SELECTED) {
        int position = findColorLabel(itemEvent.getItem());
        if ((position != -1) && (position != labels.length - 1)) {
            ColorSelectionModel selectionModel = getColorSelectionModel();
            selectionModel.setSelectedColor(colors[position]);
        }/*from  www  . j a  v  a 2  s  .c  o m*/
    }
}