javax.swing

Class JColorChooser

public class JColorChooser extends JComponent implements Accessible

A Swing widget that offers users different ways to select a color. By default, three different panels are presented to the user that are capable of changing the selected color. There are three ways to utilize JColorChooser. The first is to build a JColorChooser and add it to the content pane. The second is to use the createDialog method to create a JDialog that holds a JColorChooser. The third is to show a JColorChooser in a JDialog directly using the showDialog method.
Nested Class Summary
protected classJColorChooser.AccessibleJColorChooser
Accessibility support for JColorChooser.
Field Summary
protected AccessibleContextaccessibleContext
accessibleContext
static StringCHOOSER_PANELS_PROPERTY
The property fired by the JColorChooser when the chooserPanels property changes.
static StringPREVIEW_PANEL_PROPERTY
The property fired by the JColorChooser when the previewPanel property changes.
static StringSELECTION_MODEL_PROPERTY
The property fired by the JColorChooser when the selectionModel property changes.
Constructor Summary
JColorChooser()
This method creates a new JColorChooser with the default initial color.
JColorChooser(Color initial)
This method creates a new JColorChooser with the given initial color.
JColorChooser(ColorSelectionModel model)
This method creates a new JColorChooser with the given model.
Method Summary
voidaddChooserPanel(AbstractColorChooserPanel panel)
This method adds the given AbstractColorChooserPanel to the list of the JColorChooser's chooserPanels.
static JDialogcreateDialog(Component component, String title, boolean modal, JColorChooser chooserPane, ActionListener okListener, ActionListener cancelListener)
This method will take the given JColorChooser and place it in a JDialog with the given modal property.
AccessibleContextgetAccessibleContext()
getAccessibleContext
AbstractColorChooserPanel[]getChooserPanels()
This method returns the AbstractColorChooserPanels used with this JColorChooser.
ColorgetColor()
This method returns the current color for the JColorChooser.
booleangetDragEnabled()
DOCUMENT ME!
JComponentgetPreviewPanel()
This method returns the current previewPanel used with this JColorChooser.
ColorSelectionModelgetSelectionModel()
This method returns the ColorSelectionModel used with this JColorChooser.
ColorChooserUIgetUI()
This method returns the UI Component used for this JColorChooser.
StringgetUIClassID()
This method returns a String identifier for the UI Class to be used with the JColorChooser.
protected StringparamString()
This method returns a String describing the JColorChooser.
AbstractColorChooserPanelremoveChooserPanel(AbstractColorChooserPanel panel)
This method removes the given AbstractColorChooserPanel from the JColorChooser's list of chooserPanels.
voidsetChooserPanels(AbstractColorChooserPanel[] panels)
This method sets the chooserPanels property for this JColorChooser.
voidsetColor(Color color)
This method sets the current color for the JColorChooser.
voidsetColor(int r, int g, int b)
This method sets the current color for the JColorChooser using RGB values.
voidsetColor(int color)
This method sets the current color for the JColorChooser using the integer value.
voidsetDragEnabled(boolean b)
DOCUMENT ME!
voidsetPreviewPanel(JComponent component)
This method changes the previewPanel property for the JTabbedPane.
voidsetSelectionModel(ColorSelectionModel model)
This method sets the ColorSelectionModel to be used with this JColorChooser.
voidsetUI(ColorChooserUI ui)
This method sets the UI Component used for this JColorChooser.
static ColorshowDialog(Component component, String title, Color initial)
This method shows a JColorChooser inside a JDialog.
voidupdateUI()
This method resets the UI Component property to the Look and Feel default.

Field Detail

accessibleContext

protected AccessibleContext accessibleContext
accessibleContext

CHOOSER_PANELS_PROPERTY

public static final String CHOOSER_PANELS_PROPERTY
The property fired by the JColorChooser when the chooserPanels property changes.

PREVIEW_PANEL_PROPERTY

public static final String PREVIEW_PANEL_PROPERTY
The property fired by the JColorChooser when the previewPanel property changes.

SELECTION_MODEL_PROPERTY

public static final String SELECTION_MODEL_PROPERTY
The property fired by the JColorChooser when the selectionModel property changes.

Constructor Detail

JColorChooser

public JColorChooser()
This method creates a new JColorChooser with the default initial color.

JColorChooser

public JColorChooser(Color initial)
This method creates a new JColorChooser with the given initial color.

Parameters: initial The initial color.

JColorChooser

public JColorChooser(ColorSelectionModel model)
This method creates a new JColorChooser with the given model. The model will dictate what the initial color for the JColorChooser is.

Parameters: model The Model to use with the JColorChooser.

Method Detail

addChooserPanel

public void addChooserPanel(AbstractColorChooserPanel panel)
This method adds the given AbstractColorChooserPanel to the list of the JColorChooser's chooserPanels.

Parameters: panel The AbstractColorChooserPanel to add.

createDialog

public static JDialog createDialog(Component component, String title, boolean modal, JColorChooser chooserPane, ActionListener okListener, ActionListener cancelListener)
This method will take the given JColorChooser and place it in a JDialog with the given modal property. Three buttons are displayed in the JDialog: OK, Cancel and Reset. If OK or Cancel are pressed, the JDialog is hidden. If Reset is pressed, then the JColorChooser will take on its default color value. The given okListener will be registered to the OK button and the cancelListener will be registered to the Cancel button. If the modal property is set, then the JDialog will block until it is hidden.

Parameters: component The Component that will parent the JDialog. title The title displayed in the JDialog. modal The modal property. chooserPane The JColorChooser to place in the JDialog. okListener The ActionListener to register to the OK button. cancelListener The ActionListener to register to the Cancel button.

Returns: A JDialog with the JColorChooser inside of it.

Throws: AWTError If the component is not a suitable parent.

getAccessibleContext

public AccessibleContext getAccessibleContext()
getAccessibleContext

Returns: AccessibleContext

getChooserPanels

public AbstractColorChooserPanel[] getChooserPanels()
This method returns the AbstractColorChooserPanels used with this JColorChooser.

Returns: The AbstractColorChooserPanels used with this JColorChooser.

getColor

public Color getColor()
This method returns the current color for the JColorChooser.

Returns: The current color for the JColorChooser.

getDragEnabled

public boolean getDragEnabled()
DOCUMENT ME!

Returns: DOCUMENT ME!

getPreviewPanel

public JComponent getPreviewPanel()
This method returns the current previewPanel used with this JColorChooser.

Returns: The current previewPanel.

getSelectionModel

public ColorSelectionModel getSelectionModel()
This method returns the ColorSelectionModel used with this JColorChooser.

Returns: The ColorSelectionModel.

getUI

public ColorChooserUI getUI()
This method returns the UI Component used for this JColorChooser.

Returns: The UI Component for this JColorChooser.

getUIClassID

public String getUIClassID()
This method returns a String identifier for the UI Class to be used with the JColorChooser.

Returns: The String identifier for the UI Class.

paramString

protected String paramString()
This method returns a String describing the JColorChooser.

Returns: A String describing the JColorChooser.

removeChooserPanel

public AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel panel)
This method removes the given AbstractColorChooserPanel from the JColorChooser's list of chooserPanels.

Parameters: panel The AbstractColorChooserPanel to remove.

Returns: The AbstractColorChooserPanel that was removed.

setChooserPanels

public void setChooserPanels(AbstractColorChooserPanel[] panels)
This method sets the chooserPanels property for this JColorChooser.

Parameters: panels The new set of AbstractColorChooserPanels to use.

setColor

public void setColor(Color color)
This method sets the current color for the JColorChooser.

Parameters: color The new color for the JColorChooser.

setColor

public void setColor(int r, int g, int b)
This method sets the current color for the JColorChooser using RGB values.

Parameters: r The red value. g The green value. b The blue value.

setColor

public void setColor(int color)
This method sets the current color for the JColorChooser using the integer value. Bits 0-7 represent the blue value. Bits 8-15 represent the green value. Bits 16-23 represent the red value.

Parameters: color The new current color of the JColorChooser.

setDragEnabled

public void setDragEnabled(boolean b)
DOCUMENT ME!

Parameters: b DOCUMENT ME!

setPreviewPanel

public void setPreviewPanel(JComponent component)
This method changes the previewPanel property for the JTabbedPane. The previewPanel is responsible for indicating the current color of the JColorChooser.

Parameters: component The Component that will act as the previewPanel.

setSelectionModel

public void setSelectionModel(ColorSelectionModel model)
This method sets the ColorSelectionModel to be used with this JColorChooser.

Parameters: model The ColorSelectionModel to be used with this JColorChooser.

Throws: AWTError If the given model is null.

setUI

public void setUI(ColorChooserUI ui)
This method sets the UI Component used for this JColorChooser.

Parameters: ui The UI Component to use with this JColorChooser.

showDialog

public static Color showDialog(Component component, String title, Color initial)
This method shows a JColorChooser inside a JDialog. The JDialog will block until it is hidden. The JDialog comes with three buttons: OK, Cancel, and Reset. Pressing OK or Cancel hide the JDialog. Pressing Reset will reset the JColorChooser to its initial value.

Parameters: component The Component that parents the JDialog. title The title displayed in the JDialog. initial The initial color.

Returns: The selected color.

updateUI

public void updateUI()
This method resets the UI Component property to the Look and Feel default.