Java Platform 1.2
Beta 4

Class com.sun.java.swing.JColorChooser

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--com.sun.java.swing.JComponent
                    |
                    +--com.sun.java.swing.JColorChooser

public class JColorChooser
extends JComponent
implements Accessible
JColorChooser provides a pane of controls designed to allow a user to manipulate and select a color. This class provides 3 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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
Serialized Form

Inner Class Summary
protected   JColorChooser.AccessibleJColorChooser
          The class used to obtain the accessible context for this object.
 
Inner classes inherited from class com.sun.java.swing.JComponent
JComponent.AccessibleJComponent
 
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 com.sun.java.swing.JComponent
accessibleContext , 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
 
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(com.sun.java.swing.colorchooser.ColorSelectionModel model)
          Creates a color chooser pane with the specified ColorSelectionModel.
 
Method Summary
 void addChooserPanel(com.sun.java.swing.colorchooser.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"
 AccessibleContext getAccessibleContext()
          Get the AccessibleContext associated with this JColorChooser
 com.sun.java.swing.colorchooser.AbstractColorChooserPanel[] getChooserPanels()
           
 Color getColor()
          Gets the current color value from the color chooser.
 JComponent getPreviewPanel()
           
 com.sun.java.swing.colorchooser.ColorSelectionModel getSelectionModel()
           
 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.
 com.sun.java.swing.colorchooser.AbstractColorChooserPanel removeChooserPanel(com.sun.java.swing.colorchooser.AbstractColorChooserPanel panel)
          Removes the Color Panel specified.
 void setChooserPanels(com.sun.java.swing.colorchooser.AbstractColorChooserPanel[] panels)
           
 void setColor(Color color)
          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 setColor(int c)
          Sets the current color of the color chooser to the specified color.
 void setPreviewPanel(JComponent preview)
          Sets the current preview panel.
 void setSelectionModel(com.sun.java.swing.colorchooser.ColorSelectionModel newModel)
          Set 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 com.sun.java.swing.JComponent
addAncestorListener , addNotify , addPropertyChangeListener , addVetoableChangeListener , computeVisibleRect , contains , createToolTip , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , fireVetoableChange , getActionForKeyStroke , getAlignmentX , getAlignmentY , getAutoscrolls , getBorder , getBounds , getClientProperty , getComponentGraphics , getConditionForKeyStroke , getDebugGraphicsOptions , getGraphics , getHeight , getInsets , getInsets , getLocation , getMaximumSize , getMinimumSize , getNextFocusableComponent , getPreferredSize , getRegisteredKeyStrokes , getRootPane , getSize , getToolTipLocation , getToolTipText , getToolTipText , getTopLevelAncestor , getVisibleRect , getWidth , getX , getY , grabFocus , hasFocus , isDoubleBuffered , isFocusCycleRoot , isFocusTraversable , isLightweightComponent , isManagingFocus , isOpaque , isOptimizedDrawingEnabled , isPaintingTile , isRequestFocusEnabled , isValidateRoot , paint , paintBorder , paintChildren , paintComponent , paintImmediately , paintImmediately , processComponentKeyEvent , processFocusEvent , processKeyEvent , processMouseMotionEvent , putClientProperty , registerKeyboardAction , registerKeyboardAction , removeAncestorListener , removeNotify , removePropertyChangeListener , removeVetoableChangeListener , repaint , repaint , requestDefaultFocus , requestFocus , resetKeyboardActions , reshape , revalidate , scrollRectToVisible , setAlignmentX , setAlignmentY , setAutoscrolls , setBorder , setDebugGraphicsOptions , setDoubleBuffered , setEnabled , setMaximumSize , setMinimumSize , setNextFocusableComponent , setOpaque , setPreferredSize , setRequestFocusEnabled , setToolTipText , setUI , setVisible , unregisterKeyboardAction , update
 
Methods inherited from class java.awt.Container
add , add , add , add , add , addContainerListener , addImpl , countComponents , deliverEvent , doLayout , findComponentAt , findComponentAt , getComponent , getComponentAt , getComponentAt , getComponentCount , getComponents , getLayout , insets , invalidate , isAncestorOf , layout , list , list , locate , minimumSize , paintComponents , paramString , preferredSize , print , printComponents , processContainerEvent , processEvent , remove , remove , removeAll , removeContainerListener , setLayout , validate , validateTree
 
Methods inherited from class java.awt.Component
action , add , addComponentListener , addFocusListener , addInputMethodListener , addKeyListener , addMouseListener , addMouseMotionListener , addPropertyChangeListener , bounds , checkImage , checkImage , coalesceEvents , contains , createImage , createImage , disable , disableEvents , dispatchEvent , enable , enable , enableEvents , enableInputMethods , getBackground , getBounds , getColorModel , getComponentOrientation , getCursor , getDropTarget , getFont , getFontMetrics , getForeground , getInputContext , getInputMethodRequests , getLocale , getLocation , getLocationOnScreen , getName , getParent , getPeer , getSize , getToolkit , getTreeLock , gotFocus , handleEvent , hide , imageUpdate , inside , isDisplayable , isEnabled , isLightweight , isShowing , isValid , isVisible , keyDown , keyUp , list , list , list , location , lostFocus , mouseDown , mouseDrag , mouseEnter , mouseExit , mouseMove , mouseUp , move , nextFocus , paintAll , postEvent , prepareImage , prepareImage , printAll , processComponentEvent , processInputMethodEvent , processMouseEvent , remove , removeComponentListener , removeFocusListener , removeInputMethodListener , removeKeyListener , removeMouseListener , removeMouseMotionListener , removePropertyChangeListener , repaint , repaint , repaint , resize , resize , setBackground , setBounds , setBounds , setComponentOrientation , setCursor , setDropTarget , setFont , setForeground , setLocale , setLocation , setLocation , setName , setSize , setSize , show , show , size , toString , transferFocus
 
Methods inherited from class java.lang.Object
clone , equals , finalize , getClass , hashCode , notify , notifyAll , wait , wait , wait
 

Field Detail

SELECTION_MODEL_PROPERTY

public static final String SELECTION_MODEL_PROPERTY
The selection model property name.

PREVIEW_PANEL_PROPERTY

public static final String PREVIEW_PANEL_PROPERTY
The preview panel property name.

CHOOSER_PANELS_PROPERTY

public static final String CHOOSER_PANELS_PROPERTY
The chooserPanel array property name.

accessibleContext

protected AccessibleContext accessibleContext
Constructor Detail

JColorChooser

public JColorChooser()
Creates a color chooser pane with an initial color of white.

JColorChooser

public JColorChooser(Color initialColor)
Creates a color chooser pane with the specified initial color.
Parameters:
initialColor - the initial color set in the chooser

JColorChooser

public JColorChooser(com.sun.java.swing.colorchooser.ColorSelectionModel model)
Creates a color chooser pane with the specified ColorSelectionModel.
Parameters:
initialColor - the initial color set in the chooser
Method Detail

showDialog

public static Color showDialog(Component component,
                               String title,
                               Color initialColor)
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 null.
Parameters:
component - the parent Component for the dialog
title - the String containing the dialog's title
initialColor - the initial Color set when the color-chooser is shown

createDialog

public 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. 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.
Parameters:
c - the parent component for the dialog
title - the title for the dialog
modal - 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 dialog
okListener - the ActionListener invoked when "OK" is pressed
cancelListener - the ActionListener invoked when "Cancel" is pressed

getUI

public ColorChooserUI getUI()
Returns the L&F object that renders this component.
Returns:
the ColorChooserUI object that renders this component

setUI

public void setUI(ColorChooserUI ui)
Sets the L&F object that renders this component.
Parameters:
ui - the ColorChooserUI L&F object
See Also:
UIDefaults.getUI(com.sun.java.swing.JComponent)

updateUI

public void updateUI()
Notification from the UIManager that the L&F has changed. Replaces the current UI object with the latest version from the UIManager.
Overrides:
updateUI in class JComponent
See Also:
JComponent.updateUI()

getUIClassID

public String getUIClassID()
Returns the name of the L&F class that renders this component.
Returns:
"ColorChooserUI"
Overrides:
getUIClassID in class JComponent
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(com.sun.java.swing.JComponent)

getColor

public Color getColor()
Gets the current color value from the color chooser. By default, this delegates to the model.
Returns:
the current color value of the color chooser

setColor

public void setColor(Color color)
Sets the current color of the color chooser to the specified color. This will fire a PropertyChangeEvent for the property named "color".
Parameters:
color - the color to be set in the color chooser
See Also:
JComponent.addPropertyChangeListener(java.beans.PropertyChangeListener)

setColor

public void setColor(int r,
                     int g,
                     int b)
Sets the current color of the color chooser to the specified RGB color.
Parameters:
r - an int specifying the amount of Red
g - an int specifying the amount of Green
b - an int specifying the amount of Blue

setColor

public void setColor(int c)
Sets the current color of the color chooser to the specified color.
Parameters:
c - an int 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.

setPreviewPanel

public void setPreviewPanel(JComponent preview)
Sets the current preview panel. This will fire a PropertyChangeEvent for the property named "previewPanel".
Parameters:
color - the color to be set in the color chooser
See Also:
JComponent.addPropertyChangeListener(java.beans.PropertyChangeListener)

getPreviewPanel

public JComponent getPreviewPanel()

addChooserPanel

public void addChooserPanel(com.sun.java.swing.colorchooser.AbstractColorChooserPanel panel)
Adds a color chooser panel to the color chooser.

removeChooserPanel

public com.sun.java.swing.colorchooser.AbstractColorChooserPanel removeChooserPanel(com.sun.java.swing.colorchooser.AbstractColorChooserPanel panel)
Removes the Color Panel specified.
Parameters:
name - a string that specifies the panel to be removed

setChooserPanels

public void setChooserPanels(com.sun.java.swing.colorchooser.AbstractColorChooserPanel[] panels)

getChooserPanels

public com.sun.java.swing.colorchooser.AbstractColorChooserPanel[] getChooserPanels()

getSelectionModel

public com.sun.java.swing.colorchooser.ColorSelectionModel getSelectionModel()

setSelectionModel

public void setSelectionModel(com.sun.java.swing.colorchooser.ColorSelectionModel newModel)
Set the model containing the selected color.
Parameters:
newModel - the new ColorSelectionModel object

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JColorChooser
Specified by:
getAccessibleContext in interface Accessible
Returns:
the AccessibleContext of this JColorChooser
Overrides:
getAccessibleContext in class JComponent

Java Platform 1.2
Beta 4

Submit a bug or feature
Submit comments/suggestions about new javadoc look
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This documentation was generated with a post-Beta4 version of Javadoc.