Additional top-level classes in compilation unit: ColorChooserDialog, ColorTracker.
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:
ActionListeners can be specified to be invoked when
the user presses one of the dialog buttons.
JColorChooser panes
directly (within any container). PropertyChange listeners
can be added to detect when the current "color" property changes.
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
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 JavaBeans
has been added to the java.beans package.
Please see java..
| Modifier and Type | Class and Description |
|---|---|
| protected class | JColorChooser.
This class implements accessibility support for the
|
| Modifier and Type | Field and Description |
|---|---|
| protected AccessibleContext | accessibleContext
The accessible context.
|
| public static final String | CHOOSER_PANELS_PROPERTY
The chooserPanel array property name. |
| private AbstractColorChooserPanel[] | |
| private boolean | |
| public static final String | PREVIEW_PANEL_PROPERTY
The preview panel property name. |
| private JComponent | |
| public static final String | SELECTION_MODEL_PROPERTY
The selection model property name. |
| private ColorSelectionModel | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JColorChooser(Color
the initial color set in the chooser initialColor)Creates a color chooser pane with the specified initial color. |
| public | JColorChooser(ColorSelectionModel
the model)ColorSelectionModel to be usedCreates a color chooser pane with the specified
|
| Modifier and Type | Method and Description |
|---|---|
| public void | addChooserPanel(AbstractColorChooserPanel
the panel)AbstractColorChooserPanel to be addedAdds a color chooser panel to the color chooser. |
| public static JDialog | Returns: a new dialog containing the color-chooser panethe parent component for the dialog c, String the title for the dialog title, boolean a boolean. When true, the remainder of the program
is inactive until the dialog is closed. modal, JColorChooser the color-chooser to be placed inside the dialog chooserPane, ActionListener the ActionListener invoked when "OK" is pressed okListener, ActionListener the ActionListener invoked when "Cancel" is pressed cancelListener)Creates and returns a new dialog containing the specified
|
| public AccessibleContext | Returns: an AccessibleJColorChooser that serves as the AccessibleContext of this JColorChooserOverrides java. Implements javax. Gets the AccessibleContext associated with this JColorChooser. |
| public AbstractColorChooserPanel[] | Returns: an array ofAbstractColorChooserPanel objectsReturns the specified color panels. |
| public Color | Returns: the current color value of the color chooserGets the current color value from the color chooser. |
| public boolean | Returns: the value of thedragEnabled propertyGets the value of the |
| public JComponent | Returns: aJComponent object -- the preview panelReturns the preview panel that shows a chosen color. |
| public ColorSelectionModel | Returns: aColorSelectionModel objectReturns the data model that handles color selections. |
| public ColorChooserUI | Returns: theColorChooserUI object that renders
this componentOverrides javax. Returns the L&F object that renders this component. |
| public String | Returns: the string "ColorChooserUI"Overrides javax. Returns the name of the L&F class that renders this component. |
| protected String | Returns: a string representation of thisJColorChooserOverrides javax. Returns a string representation of this |
| public AbstractColorChooserPanel | Returns: the color panela string that specifies the panel to be removed panel)Removes the Color Panel specified. |
| public void | setChooserPanels(AbstractColorChooserPanel[]
an array of panels)AbstractColorChooserPanel
objectsSpecifies the Color Panels used to choose a color value. |
| public void | |
| public void | setColor(int
an int specifying the amount of Red r, int an int specifying the amount of Green g, int an int specifying the amount of Blue b)Sets the current color of the color chooser to the specified RGB color. |
| public void | setColor(int
an integer value that sets the current color in the chooser
where the low-order 8 bits specify the Blue value,
the next 8 bits specify the Green value, and the 8 bits
above that specify the Red value. c)Sets the current color of the color chooser to the specified color. |
| public void | setDragEnabled(boolean
the value to set the b)dragEnabled property toSets the |
| public void | setPreviewPanel(JComponent
the preview)JComponent which displays the current colorSets the current preview panel. |
| public void | setSelectionModel(ColorSelectionModel
the new newModel)ColorSelectionModel objectSets the model containing the selected color. |
| public void | setUI(ColorChooserUI
the ui)ColorChooserUI L&F objectSets the L&F object that renders this component. |
| public static Color | Returns: the selected color ornull if the user opted outthe parent component, String Component for the dialogthe String containing the dialog's title title, Color the initial Color set when the color-chooser is shown initialColor)Shows a modal color-chooser dialog and blocks until the dialog is hidden. |
| public static Color | Returns: the selected color ornull if the user opted outthe parent component, String Component for the dialogthe String containing the dialog's title title, Color the initial Color set when the color-chooser is shown initialColor, boolean true if the transparency of
a color can be selected colorTransparencySelectionEnabled)Shows a modal color-chooser dialog and blocks until the dialog is hidden. |
| public void | updateUI()
Overrides javax. Notification from the |
| private void | writeObject(ObjectOutputStream s)
Hides javax. See |
| accessibleContext | back to summary |
|---|---|
| protected AccessibleContext accessibleContext Hides java. The accessible context. | |
| CHOOSER_PANELS_PROPERTY | back to summary |
|---|---|
| public static final String CHOOSER_PANELS_PROPERTY The chooserPanel array property name. | |
| chooserPanels | back to summary |
|---|---|
| private AbstractColorChooserPanel[] chooserPanels | |
| dragEnabled | back to summary |
|---|---|
| private boolean dragEnabled | |
| PREVIEW_PANEL_PROPERTY | back to summary |
|---|---|
| public static final String PREVIEW_PANEL_PROPERTY The preview panel property name. | |
| previewPanel | back to summary |
|---|---|
| private JComponent previewPanel | |
| SELECTION_MODEL_PROPERTY | back to summary |
|---|---|
| public static final String SELECTION_MODEL_PROPERTY The selection model property name. | |
| selectionModel | back to summary |
|---|---|
| private ColorSelectionModel selectionModel | |
| uiClassID | back to summary |
|---|---|
| private static final String uiClassID Hides javax.
| |
| JColorChooser | back to summary |
|---|---|
| public JColorChooser() Creates a color chooser pane with an initial color of white. | |
| JColorChooser | back to summary |
|---|---|
| public JColorChooser(Color initialColor) Creates a color chooser pane with the specified initial color.
| |
| JColorChooser | back to summary |
|---|---|
| public JColorChooser(ColorSelectionModel model) Creates a color chooser pane with the specified
| |
| addChooserPanel | back to summary |
|---|---|
| public void addChooserPanel(AbstractColorChooserPanel panel) Adds a color chooser panel to the color chooser.
| |
| createDialog | back to summary |
|---|---|
| public static JDialog createDialog(Component c, String title, boolean modal, JColorChooser chooserPane, ActionListener okListener, ActionListener cancelListener) throws HeadlessException Creates and returns a new dialog containing the specified
| |
| getAccessibleContext | back to summary |
|---|---|
| public AccessibleContext getAccessibleContext() Overrides java. Implements javax. Gets the AccessibleContext associated with this JColorChooser. For color choosers, the AccessibleContext takes the form of an AccessibleJColorChooser. A new AccessibleJColorChooser instance is created if necessary.
| |
| getChooserPanels | back to summary |
|---|---|
| public AbstractColorChooserPanel[] getChooserPanels() Returns the specified color panels.
| |
| getColor | back to summary |
|---|---|
| public Color getColor() Gets the current color value from the color chooser. By default, this delegates to the model.
| |
| getDragEnabled | back to summary |
|---|---|
| public boolean getDragEnabled() Gets the value of the
| |
| getPreviewPanel | back to summary |
|---|---|
| public JComponent getPreviewPanel() Returns the preview panel that shows a chosen color.
| |
| getSelectionModel | back to summary |
|---|---|
| public ColorSelectionModel getSelectionModel() Returns the data model that handles color selections.
| |
| getUI | back to summary |
|---|---|
| public ColorChooserUI getUI() Overrides javax. Returns the L&F object that renders this component.
| |
| getUIClassID | back to summary |
|---|---|
| public String getUIClassID() Overrides javax. Returns the name of the L&F class that renders this component.
| |
| paramString | back to summary |
|---|---|
| protected String paramString() Overrides javax. Returns a string representation of this
| |
| removeChooserPanel | back to summary |
|---|---|
| public AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel panel) Removes the Color Panel specified.
| |
| setChooserPanels | back to summary |
|---|---|
| public void setChooserPanels(AbstractColorChooserPanel[] panels) Specifies the Color Panels used to choose a color value.
| |
| setColor | back to summary |
|---|---|
| public void setColor(Color color) Sets the current color of the color chooser to the specified color.
The
| |
| setColor | back to summary |
|---|---|
| public void setColor(int r, int g, int b) Sets the current color of the color chooser to the specified RGB color. Note that the values of red, green, and blue should be between the numbers 0 and 255, inclusive.
| |
| setColor | back to summary |
|---|---|
| public void setColor(int c) Sets the current color of the color chooser to the specified color.
| |
| setDragEnabled | back to summary |
|---|---|
| public void setDragEnabled(boolean b) Sets the
When automatic drag handling is enabled,
most look and feels begin a drag-and-drop operation
when the user presses the mouse button over the preview panel.
Some look and feels might not support automatic drag and drop;
they will ignore this property. You can work around such
look and feels by modifying the component
to directly call the
| |
| setPreviewPanel | back to summary |
|---|---|
| public void setPreviewPanel(JComponent preview) Sets the current preview panel.
This will fire a
| |
| setSelectionModel | back to summary |
|---|---|
| public void setSelectionModel(ColorSelectionModel newModel) Sets the model containing the selected color.
| |
| setUI | back to summary |
|---|---|
| public void setUI(ColorChooserUI ui) Sets the L&F object that renders this component.
| |
| showDialog | back to summary |
|---|---|
| public static Color showDialog(Component component, String title, Color initialColor) throws HeadlessException Shows a modal color-chooser dialog and blocks until the
dialog is hidden. If the user presses the "OK" button, then
this method hides/disposes the dialog and returns the selected color.
If the user presses the "Cancel" button or closes the dialog without
pressing "OK", then this method hides/disposes the dialog and returns
| |
| showDialog | back to summary |
|---|---|
| public static Color showDialog(Component component, String title, Color initialColor, boolean colorTransparencySelectionEnabled) throws HeadlessException Shows a modal color-chooser dialog and blocks until the
dialog is hidden. If the user presses the "OK" button, then
this method hides/disposes the dialog and returns the selected color.
If the user presses the "Cancel" button or closes the dialog without
pressing "OK", then this method hides/disposes the dialog and returns
| |
| updateUI | back to summary |
|---|---|
| public void updateUI() Overrides javax. Notification from the
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Hides javax. See
| |
JColorChooser class. It provides an implementation of the
Java Accessibility API appropriate to color chooser user-interface
elements.
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides javax. Get the role of this object. |
| AccessibleJColorChooser | back to summary |
|---|---|
| protected AccessibleJColorChooser() Constructs an | |
| getAccessibleRole | back to summary |
|---|---|
| public AccessibleRole getAccessibleRole() Overrides javax. Get the role of this object.
| |