public class ColorChooser extends JComponent
By default, supports two sets of palettes - a set of 4 continuous palettes
and a set of 4 tiled, fixed palettes (the SVG/X palette, Swing/AWT palettes
and a history of recently selected colors). Whether the tiled or continuous
palettes are given precedence depends on the property
continuousPalettePreferred
.
Palettes are pluggable, so it is possible to provide your own implementation(s) of Palette to be displayed when the component is clicked.
Typical usage: Attach an ActionListener; it will be notified when the user selects a color.
To catch colors as the user selects, listen for PROP_TRANSIENT_COLOR. The component will fire changes in PROP_COLOR along with actin events, when the user selects a color. PROP_COLOR changes are fired both in response to use actions and programmatic changes to the color property.
JComponent.AccessibleJComponent
Component.BaselineResizeBehavior
Modifier and Type | Field and Description |
---|---|
static String |
PROP_COLOR
Property name for property fired when the color property changes.
|
static String |
PROP_CONTINUOUS_PALETTE
Fired when the value of the continuous palette changes.
|
static String |
PROP_PICKER_VISIBLE
Property indicating the visibility of the popup palette.
|
static String |
PROP_TRANSIENT_COLOR
Property name for property fired when the transient color property (the
color while the user is selecting) changes.
|
static String |
UI_CLASS_ID
UI Class ID under which the UI delegate class is stored in UIManager (see
UIManager.getUI()).
|
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
ColorChooser()
Create a color chooser
|
ColorChooser(Color initialColor)
Create a color chooser initialized to the passed color, defaulted to show
a continuous palette on initial click.
|
ColorChooser(Palette[] palettes)
Create a color chooser with the passed array of 8 or fewer palettes.
|
ColorChooser(Palette[] palettes,
Color initialColor)
Create a color chooser with the passed array of 8 palettes and
initialized with the passed color.
|
Modifier and Type | Method and Description |
---|---|
void |
addActionListener(ActionListener listener)
Registers ActionListener to receive events.
|
static String |
colorToString(Color c)
Get a string representation of a color, if possible returning a named,
localized constant if the passed color matches one of the SVG constants;
else returning a String representing RGB values.
|
Color |
getColor()
Get the color currently represented by this component.
|
static String |
getColorName(Color color)
Returns the SVG or Swing constant name for the passed color, if the color
exactly matches a color in the Swing UIManager constants or the
SVG/X-Windows constants.
|
Palette[] |
getPalettes()
Get the array of palettes that will be displayed when the user clicks
this color chooser component and holds down various keys.
|
Color |
getTransientColor()
Returns the currently displayed color which may not be the same as the
value of
getColor() but is the color currently displayed as
the user moves the mouse to select the color. |
String |
getUIClassId()
Overridden to return
UI_CLASS_ID |
boolean |
isContinuousPalettePreferred()
Determine whether the initial palette shown when clicked with no keys
pressed is one showing a continuous (rainbow) palette or a set of tiles
with different colors.
|
void |
removeActionListener(ActionListener listener)
Removes ActionListener from the list of listeners.
|
void |
setColor(Color c)
Set the color this color chooser currently represents.
|
void |
setContinuousPalettePreferred(boolean val)
Set whether the initial palette shown when clicked with no keys pressed
is one showing a continuous (rainbow) palette or a set of tiles with
different colors.
|
void |
setPalettes(Palette[] palettes)
Set the Palette objects this color chooser will display.
|
void |
updateUI() |
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final String UI_CLASS_ID
"nbColorChooserUI"
public static final String PROP_COLOR
public static final String PROP_TRANSIENT_COLOR
public static final String PROP_CONTINUOUS_PALETTE
public static final String PROP_PICKER_VISIBLE
public ColorChooser()
public ColorChooser(Color initialColor)
initialColor
- public ColorChooser(Palette[] palettes, Color initialColor)
palettes
- initialColor
- public ColorChooser(Palette[] palettes)
palettes
- public String getUIClassId()
UI_CLASS_ID
public void updateUI()
updateUI
in class JComponent
public Color getColor()
public void setColor(Color c)
PROP_COLOR
but will not trigger an action
event to be fired.c
- public Color getTransientColor()
getColor()
but is the color currently displayed as
the user moves the mouse to select the color.getColor()
).PROP_TRANSIENT_COLOR
,
setTransientColor(java.awt.Color)
public static String colorToString(Color c)
c
- public static String getColorName(Color color)
color
- public void setContinuousPalettePreferred(boolean val)
val
- The value, true to show a continuous palette by defaultpublic boolean isContinuousPalettePreferred()
TRUE
.public void setPalettes(Palette[] palettes)
Which palette is shown to the user depends on what if any control keys are being held when the user initially clicks or presses while dragging the mouse to select. The mapping between key combinations and palette entries is:
palettes
- public Palette[] getPalettes()
public void addActionListener(ActionListener listener)
JColorChooser
.listener
- The listener to register.public void removeActionListener(ActionListener listener)
JColorChooser
(note they are
not fired if you call setColor()
).listener
- The listener to remove.Jas4pp 1.5 © Java Analysis Studio for Particle Physics