|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--javax.swing.JColorChooser
Safe: 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:
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 java.beans.XMLEncoder
.
Field Summary | |
protected AccessibleContext |
accessibleContext
|
static String |
CHOOSER_PANELS_PROPERTY
Suppressed: The chooserPanel array property name. |
private javax.swing.colorchooser.AbstractColorChooserPanel[] |
chooserPanels
|
private boolean |
dragEnabled
|
static String |
PREVIEW_PANEL_PROPERTY
Suppressed: The preview panel property name. |
private JComponent |
previewPanel
|
static String |
SELECTION_MODEL_PROPERTY
Suppressed: The selection model property name. |
private javax.swing.colorchooser.ColorSelectionModel |
selectionModel
|
private static String |
uiClassID
|
Fields inherited from class javax.swing.JComponent |
_bounds, listenerList, paintingChild, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Container |
|
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Constructor Summary | |
JColorChooser()
Enabled: Creates a color chooser pane with an initial color of white. |
|
JColorChooser(Color initialColor)
Enabled: Creates a color chooser pane with the specified initial color. |
|
JColorChooser(javax.swing.colorchooser.ColorSelectionModel model)
Enabled: Creates a color chooser pane with the specified ColorSelectionModel . |
Method Summary | |
void |
addChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel panel)
Enabled: Adds a color chooser panel to the color chooser. |
static JDialog |
createDialog(Component c,
String title,
boolean modal,
JColorChooser chooserPane,
ActionListener okListener,
ActionListener cancelListener)
Enabled: Creates and returns a new dialog containing the specified ColorChooser pane along with "OK", "Cancel", and "Reset"
buttons. |
AccessibleContext |
getAccessibleContext()
Suppressed: Gets the AccessibleContext associated with this JColorChooser. |
javax.swing.colorchooser.AbstractColorChooserPanel[] |
getChooserPanels()
Enabled: Returns the specified color panels. |
Color |
getColor()
Enabled: Gets the current color value from the color chooser. |
boolean |
getDragEnabled()
Enabled: Gets the value of the dragEnabled property. |
JComponent |
getPreviewPanel()
Enabled: Returns the preview panel that shows a chosen color. |
javax.swing.colorchooser.ColorSelectionModel |
getSelectionModel()
Enabled: Returns the data model that handles color selections. |
javax.swing.plaf.ColorChooserUI |
getUI()
Suppressed: Returns the L&F object that renders this component. |
String |
getUIClassID()
Suppressed: Returns the name of the L&F class that renders this component. |
protected String |
paramString()
Returns a string representation of this JColorChooser . |
javax.swing.colorchooser.AbstractColorChooserPanel |
removeChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel panel)
Enabled: Removes the Color Panel specified. |
void |
setChooserPanels(javax.swing.colorchooser.AbstractColorChooserPanel[] panels)
Enabled: Specifies the Color Panels used to choose a color value. |
void |
setColor(Color color)
Enabled: Sets the current color of the color chooser to the specified color. |
void |
setColor(int c)
Enabled: Sets the current color of the color chooser to the specified color. |
void |
setColor(int r,
int g,
int b)
Enabled: Sets the current color of the color chooser to the specified RGB color. |
void |
setDragEnabled(boolean b)
Enabled: 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)
Enabled: Sets the current preview panel. |
void |
setSelectionModel(javax.swing.colorchooser.ColorSelectionModel newModel)
Enabled: Sets the model containing the selected color. |
void |
setUI(javax.swing.plaf.ColorChooserUI ui)
Suppressed: Sets the L&F object that renders this component. |
static Color |
showDialog(Component component,
String title,
Color initialColor)
Enabled: Shows a modal color-chooser dialog and blocks until the dialog is hidden. |
void |
updateUI()
Suppressed: Notification from the UIManager that the L&F has changed. |
private void |
writeObject(ObjectOutputStream s)
See readObject and writeObject in
JComponent for more
information about serialization in Swing. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private static final String uiClassID
getUIClassID()
,
JComponent.readObject(java.io.ObjectInputStream)
private javax.swing.colorchooser.ColorSelectionModel selectionModel
private JComponent previewPanel
private javax.swing.colorchooser.AbstractColorChooserPanel[] chooserPanels
private boolean dragEnabled
public static final String SELECTION_MODEL_PROPERTY
public static final String PREVIEW_PANEL_PROPERTY
public static final String CHOOSER_PANELS_PROPERTY
protected AccessibleContext accessibleContext
Constructor Detail |
public JColorChooser()
public JColorChooser(Color initialColor)
initialColor
- the initial color set in the chooserpublic JColorChooser(javax.swing.colorchooser.ColorSelectionModel model)
ColorSelectionModel
.
model
- the ColorSelectionModel
to be usedMethod Detail |
public static Color showDialog(Component component, String title, Color initialColor) throws HeadlessException
null
.
component
- the parent Component
for the dialogtitle
- the String containing the dialog's titleinitialColor
- the initial Color set when the color-chooser is shown
null
if the user opted out
HeadlessException
java.awt.GraphicsEnvironment#isHeadless
public static JDialog createDialog(Component c, String title, boolean modal, JColorChooser chooserPane, ActionListener okListener, ActionListener cancelListener) throws HeadlessException
ColorChooser
pane along with "OK", "Cancel", and "Reset"
buttons. If the "OK" or "Cancel" buttons are pressed, the dialog is
automatically hidden (but not disposed). If the "Reset"
button is pressed, the color-chooser's color will be reset to the
color which was set the last time show
was invoked on the
dialog and the dialog will remain showing.
c
- the parent component for the dialogtitle
- the title for the dialogmodal
- a boolean. When true, the remainder of the program
is inactive until the dialog is closed.chooserPane
- the color-chooser to be placed inside the dialogokListener
- the ActionListener invoked when "OK" is pressedcancelListener
- the ActionListener invoked when "Cancel" is pressed
HeadlessException
java.awt.GraphicsEnvironment#isHeadless
public javax.swing.plaf.ColorChooserUI getUI()
ColorChooserUI
object that renders
this componentpublic void setUI(javax.swing.plaf.ColorChooserUI ui)
ui
- the ColorChooserUI
L&F objectUIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
UIManager
that the L&F has changed.
Replaces the current UI object with the latest version from the
UIManager
.
updateUI
in class JComponent
JComponent.updateUI()
public String getUIClassID()
getUIClassID
in class JComponent
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
public Color getColor()
public void setColor(Color color)
ColorSelectionModel
will fire a ChangeEvent
color
- the color to be set in the color chooserJComponent.addPropertyChangeListener(java.beans.PropertyChangeListener)
public void setColor(int r, int g, int b)
r
- an int specifying the amount of Redg
- an int specifying the amount of Greenb
- an int specifying the amount of Bluejava.awt.Color
public void setColor(int c)
c
- 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.public void setDragEnabled(boolean b)
dragEnabled
property,
which must be true
to enable
automatic drag handling (the first part of drag and drop)
on this component.
The transferHandler
property needs to be set
to a non-null
value for the drag to do
anything. The default value of the dragEnabled
property
is false
.
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 exportAsDrag
method of a
TransferHandler
.
b
- the value to set the dragEnabled
property tojava.awt.GraphicsEnvironment#isHeadless
,
getDragEnabled()
,
JComponent.setTransferHandler(javax.swing.TransferHandler)
,
TransferHandler
public boolean getDragEnabled()
dragEnabled
property.
dragEnabled
propertysetDragEnabled(boolean)
public void setPreviewPanel(JComponent preview)
PropertyChangeEvent
for the property
named "previewPanel".
preview
- the JComponent
which displays the current colorJComponent.addPropertyChangeListener(java.beans.PropertyChangeListener)
public JComponent getPreviewPanel()
JComponent
object -- the preview panelpublic void addChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel panel)
panel
- the AbstractColorChooserPanel
to be addedpublic javax.swing.colorchooser.AbstractColorChooserPanel removeChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel panel)
public void setChooserPanels(javax.swing.colorchooser.AbstractColorChooserPanel[] panels)
panels
- an array of AbstractColorChooserPanel
objectspublic javax.swing.colorchooser.AbstractColorChooserPanel[] getChooserPanels()
AbstractColorChooserPanel
objectspublic javax.swing.colorchooser.ColorSelectionModel getSelectionModel()
ColorSelectionModel
objectpublic void setSelectionModel(javax.swing.colorchooser.ColorSelectionModel newModel)
newModel
- the new ColorSelectionModel
objectprivate void writeObject(ObjectOutputStream s) throws IOException
readObject
and writeObject
in
JComponent
for more
information about serialization in Swing.
s
- the ObjectOutputStream
in which to write
IOException
protected String paramString()
JColorChooser
.
This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null
.
paramString
in class JComponent
JColorChooser
public AccessibleContext getAccessibleContext()
getAccessibleContext
in interface Accessible
getAccessibleContext
in class JComponent
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |