javax.swing
Class JColorChooser

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JColorChooser
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable
public class JColorChooser
extends JComponent
implements Accessible

JColorChooser provides a pane of controls designed to allow a user to manipulate and select a color. For information about using color choosers, see How to Use Color Choosers, a section in The Java Tutorial.

This class provides three levels of API:

  1. A static convenience method which shows a modal color-chooser dialog and returns the color selected by the user.
  2. A static convenience method for creating a color-chooser dialog where ActionListeners can be specified to be invoked when the user presses one of the dialog buttons.
  3. The ability to create instances of JColorChooser panes directly (within any container). PropertyChange listeners can be added to detect when the current "color" property changes.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

 

Nested Class Summary

protected  class JColorChooser.AccessibleJColorChooser
    This class implements accessibility support for the JColorChooser class.
 
Nested classes inherited from class javax.swing.JComponent
 
Nested classes inherited from class java.awt.Container
 
Nested classes inherited from class java.awt.Component
Component.BltBufferStrategy, Component.FlipBufferStrategy
 

 

Field Summary

protected  AccessibleContext accessibleContext
    
static String CHOOSER_PANELS_PROPERTY
    The chooserPanel array property name.
static String PREVIEW_PANEL_PROPERTY
    The preview panel property name.
static String SELECTION_MODEL_PROPERTY
    The selection model property name.
 
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 

 

Constructor Summary

JColorChooser()
    Creates a color chooser pane with an initial color of white.
JColorChooser(Color initialColor)
    Creates a color chooser pane with the specified initial color.
JColorChooser(ColorSelectionModel model)
    Creates a color chooser pane with the specified ColorSelectionModel.
 

 

Method Summary

 void addChooserPanel(AbstractColorChooserPanel panel)
    Adds a color chooser panel to the color chooser.
static JDialog createDialog(Component c, String title, boolean modal, JColorChooser chooserPane, ActionListener okListener, ActionListener cancelListener)
    Creates and returns a new dialog containing the specified ColorChooser pane along with "OK", "Cancel", and "Reset" buttons.
 AccessibleContext getAccessibleContext()
    Gets the AccessibleContext associated with this JColorChooser.
 AbstractColorChooserPanel[] getChooserPanels()
    Returns the specified color panels.
 Color getColor()
    Gets the current color value from the color chooser.
 boolean getDragEnabled()
    Gets the value of the dragEnabled property.
 JComponent getPreviewPanel()
    Returns the preview panel that shows a chosen color.
 ColorSelectionModel getSelectionModel()
    Returns the data model that handles color selections.
 ColorChooserUI getUI()
    Returns the L&F object that renders this component.
 String getUIClassID()
    Returns the name of the L&F class that renders this component.
protected  String paramString()
    Returns a string representation of this JColorChooser.
 AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel panel)
    Removes the Color Panel specified.
 void setChooserPanels(AbstractColorChooserPanel[] panels)
    Specifies the Color Panels used to choose a color value.
 void setColor(Color color)
    Sets the current color of the color chooser to the specified color.
 void setColor(int c)
    Sets the current color of the color chooser to the specified color.
 void setColor(int r, int g, int b)
    Sets the current color of the color chooser to the specified RGB color.
 void setDragEnabled(boolean b)
    Sets the dragEnabled property, which must be true to enable automatic drag handling (the first part of drag and drop) on this component.
 void setPreviewPanel(JComponent preview)
    Sets the current preview panel.
 void setSelectionModel(ColorSelectionModel newModel)
    Sets the model containing the selected color.
 void setUI(ColorChooserUI ui)
    Sets the L&F object that renders this component.
static Color showDialog(Component component, String title, Color initialColor)
    Shows a modal color-chooser dialog and blocks until the dialog is hidden.
 void updateUI()
    Notification from the UIManager that the L&F has changed.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX,