Getting and Setting the Selected Color in a JColorChooser Dialog - Java Swing

Java examples for Swing:JColorChooser

Description

Getting and Setting the Selected Color in a JColorChooser Dialog

Demo Code

import java.awt.Color;

import javax.swing.JColorChooser;

public class Main {
  public static void main(String[] argv) {
    // Create the chooser
    JColorChooser chooser = new JColorChooser();

    // Set the selected color
    chooser.setColor(Color.red);//from  w  ww. j  a va  2s  . c  o  m

    // Create and show dialog.
    // See Creating a JColorChooser Dialog.

    // Get current selected color
    Color color = chooser.getColor();
  }

}

Related Tutorials