Java Code Examples for javax.swing.colorchooser.ColorSelectionModel#setSelectedColor()

The following examples show how to use javax.swing.colorchooser.ColorSelectionModel#setSelectedColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DarkSwatchesChooserPanel.java    From darklaf with MIT License 5 votes vote down vote up
protected void setSelectedColor(final Color color) {
    ColorSelectionModel model = getColorSelectionModel();
    previewPanel.setColor(color);
    if (model != null) {
        model.setSelectedColor(color);
    }
}
 
Example 2
Source File: DarkColorChooserPanel.java    From darklaf with MIT License 5 votes vote down vote up
@Override
public void colorChanged(final Color color, final Object source) {
    if (isChanging || color == null) return;
    isChanging = true;
    currentColor = color;
    ColorSelectionModel model = getColorSelectionModel();
    if (model != null) model.setSelectedColor(currentColor);
    applyColorToFields(color);
    if (source != textHex) textHex.setValue(color);
    previewComponent.setColor(color);
    colorWheelPanel.setColor(color, this);
    isChanging = false;
}
 
Example 3
Source File: AlphaColorChooserPanel.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
private void alphaSliderStateChanged(javax.swing.event.ChangeEvent evt) { // GEN-FIRST:event_alphaSliderStateChanged

    int v = alphaSlider.getValue();
    alphaTxt.setText(Integer.toString(v));

    ColorSelectionModel csm = getColorSelectionModel();
    if (csm != null) {
      Color c = csm.getSelectedColor();
      Color nc = v < 255 ? new Color(c.getRed(), c.getGreen(), c.getBlue(), v)
          : new Color(c.getRed(), c.getGreen(), c.getBlue());
      csm.setSelectedColor(nc);
    }
  }
 
Example 4
Source File: StreetsJColorChooserPanel.java    From VanetSim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * An implemented <code>ItemListener</code> to change colors when user changes value in the <code>comboBox</code>.
 * 
 * @param itemEvent	the received event
 * 
 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
 */
public void itemStateChanged(ItemEvent itemEvent) {
	int state = itemEvent.getStateChange();
	if (state == ItemEvent.SELECTED) {
		int position = findColorLabel(itemEvent.getItem());
		if (position != -1) {
			ColorSelectionModel selectionModel = getColorSelectionModel();
			selectionModel.setSelectedColor(COLORS[position]);
		}
	}
}
 
Example 5
Source File: ColorPalettesChooser.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setColorToModel(Color color) {
	ColorSelectionModel colorSelectionModel = getColorSelectionModel();
	if (colorSelectionModel != null) {
		colorSelectionModel.setSelectedColor(color);
	}
}