The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.colorchooser  [10 examples]

e877. Getting and Setting the Selected Color in a JColorChooser Dialog

Normally, the color is retrieved from a color chooser dialog when the dialog is closed. See e884 Listening for OK and Cancel Events in a JColorChooser Dialog for an example of how to determine when the dialog is closed.
    // Create the chooser
    JColorChooser chooser = new JColorChooser();
    
    // Set the selected color
    chooser.setColor(Color.red);
    
    // Create and show dialog.
    // See e876 Creating a JColorChooser Dialog.
    
    // Get current selected color
    Color color = chooser.getColor();

 Related Examples
e876. Creating a JColorChooser Dialog

See also: Color Chooser Panel    Events    Preview Panel   


© 2002 Addison-Wesley.