public class JColorChooser extends JComponent implements Accessible
JColorChooser
提供了一个设计用于允许用户操纵和选择颜色的控件窗格。
有关使用颜色选择器的信息,请参阅Java Tutorial中的 How to Use Color Choosers 。
这个类提供了三个级别的API:
ActionListeners
当用户按下该对话框按钮中的一个将被调用可以被指定。 JColorChooser
直接窗格(任何容器内)。 PropertyChange
可以添加PropertyChange
器,以检测当前的“color”属性何时更改。 警告: Swing不是线程安全的。 欲了解更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4版本开始,对所有JavaBeans的长期存储的支持已经添加到java.beans
包中。 请参阅XMLEncoder
。
Modifier and Type | Class and Description |
---|---|
protected class |
JColorChooser.AccessibleJColorChooser
这个类实现了可访问性支持
JColorChooser 类。
|
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected AccessibleContext |
accessibleContext |
static String |
CHOOSER_PANELS_PROPERTY
chooserPanel数组属性名称。
|
static String |
PREVIEW_PANEL_PROPERTY
预览面板属性名称。
|
static String |
SELECTION_MODEL_PROPERTY
选择模型属性名称。
|
listenerList, TOOL_TIP_TEXT_KEY, ui, 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 |
---|
JColorChooser()
创建一个初始颜色为白色的颜色选择器窗格。
|
JColorChooser(Color initialColor)
创建具有指定初始颜色的颜色选择器窗格。
|
JColorChooser(ColorSelectionModel model)
创建具有指定颜色选取器窗格
ColorSelectionModel 。
|
Modifier and Type | Method and Description |
---|---|
void |
addChooserPanel(AbstractColorChooserPanel panel)
在颜色选择器中添加一个颜色选择器面板。
|
static JDialog |
createDialog(Component c, String title, boolean modal, JColorChooser chooserPane, ActionListener okListener, ActionListener cancelListener)
创建并返回一个包含指定的
ColorChooser 窗格的新对话框以及“确定”,“取消”和“重置”按钮。
|
AccessibleContext |
getAccessibleContext()
获取与此JColorChooser关联的AccessibleContext。
|
AbstractColorChooserPanel[] |
getChooserPanels()
返回指定的颜色面板。
|
Color |
getColor()
从颜色选择器获取当前颜色值。
|
boolean |
getDragEnabled()
获取
dragEnabled 属性的值。
|
JComponent |
getPreviewPanel()
返回显示所选颜色的预览面板。
|
ColorSelectionModel |
getSelectionModel()
返回处理颜色选择的数据模型。
|
ColorChooserUI |
getUI()
返回渲染此组件的L&F对象。
|
String |
getUIClassID()
返回呈现此组件的L&F类的名称。
|
protected String |
paramString()
返回此
JColorChooser 的字符串表示
JColorChooser 。
|
AbstractColorChooserPanel |
removeChooserPanel(AbstractColorChooserPanel panel)
删除指定的颜色面板。
|
void |
setChooserPanels(AbstractColorChooserPanel[] panels)
指定用于选择颜色值的颜色面板。
|
void |
setColor(Color color)
将颜色选择器的当前颜色设置为指定的颜色。
|
void |
setColor(int c)
将颜色选择器的当前颜色设置为指定的颜色。
|
void |
setColor(int r, int g, int b)
将颜色选择器的当前颜色设置为指定的RGB颜色。
|
void |
setDragEnabled(boolean b)
设置
dragEnabled 属性,该属性必须为
true 以启用此组件上的自动拖放处理(拖放的第一部分)。
|
void |
setPreviewPanel(JComponent preview)
设置当前预览面板。
|
void |
setSelectionModel(ColorSelectionModel newModel)
设置包含所选颜色的模型。
|
void |
setUI(ColorChooserUI ui)
设置渲染此组件的L&F对象。
|
static Color |
showDialog(Component component, String title, Color initialColor)
显示模态颜色选择器对话框并阻塞,直到对话框被隐藏。
|
void |
updateUI()
通知从
UIManager ,L&F已经改变。
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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 SELECTION_MODEL_PROPERTY
public static final String PREVIEW_PANEL_PROPERTY
public static final String CHOOSER_PANELS_PROPERTY
protected AccessibleContext accessibleContext
public JColorChooser()
public JColorChooser(Color initialColor)
initialColor
- 在选择器中设置的初始颜色
public JColorChooser(ColorSelectionModel model)
ColorSelectionModel
。
model
- 要使用的
ColorSelectionModel
public static Color showDialog(Component component, String title, Color initialColor) throws HeadlessException
null
。
component
- 对话框的父级
Component
title
- 包含对话框标题的字符串
initialColor
- 显示颜色选择器时的初始颜色设置
null
如果用户选择退出
HeadlessException
- 如果GraphicsEnvironment.isHeadless()返回true。
GraphicsEnvironment.isHeadless()
public static JDialog createDialog(Component c, String title, boolean modal, JColorChooser chooserPane, ActionListener okListener, ActionListener cancelListener) throws HeadlessException
ColorChooser
“确定”,“取消”一起窗格和“Reset”按钮。
如果按下“确定”或“取消”按钮,对话框将自动隐藏(但不处理)。
如果按下“复位”按钮,颜色选择器的颜色将被重置为在对话框上调用最后一次show
设置的颜色,对话框将保持显示。
c
- 对话框的父组件
title
- 对话框的标题
modal
- 一个布尔值。
当为真时,程序的其余部分不活动,直到对话框关闭。
chooserPane
- 要放置在对话框内的颜色选择器
okListener
- 按“OK”时调用ActionListener
cancelListener
- 当按下“取消”时调用ActionListener
HeadlessException
- 如果GraphicsEnvironment.isHeadless()返回true。
GraphicsEnvironment.isHeadless()
public ColorChooserUI getUI()
ColorChooserUI
对象
public void setUI(ColorChooserUI ui)
ui
-
ColorChooserUI
L&F对象
UIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
UIManager
表明L&F已经改变了。
从UIManager
替换最新版本的当前UI对象。
updateUI
在
JComponent
JComponent.updateUI()
public String getUIClassID()
getUIClassID
在
JComponent
类
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
public Color getColor()
public void setColor(Color color)
ColorSelectionModel
将发射一个ChangeEvent
color
- 要在颜色选择器中设置的颜色
Container.addPropertyChangeListener(java.beans.PropertyChangeListener)
public void setColor(int r, int g, int b)
r
- 一个指定红色数量的int
g
- 一个指定绿色量的int
b
- 指定蓝色数量的int
IllegalArgumentException
- 如果r,g,b值超出范围
Color
public void setColor(int c)
c
- 一个整数值,用于设置低位8位指定蓝色值的选择器中的当前颜色,接下来的8位指定绿色值,高8位指定红色值。
public void setDragEnabled(boolean b)
dragEnabled
属性,该属性必须为true
以启用此组件上的自动拖放处理(第一部分拖放)。
transferHandler
属性需要设置为非null
值来拖动才能执行任何操作。
dragEnabled
属性的默认值为false
。
当启用自动拖动处理时,当用户在预览面板上按下鼠标按钮时,大多数外观和感觉开始拖放操作。 有些外观和感觉可能不支持自动拖放; 他们将忽略此属性。 您可以解决这样的外观和修改组件以直接调用感觉exportAsDrag
一个的方法TransferHandler
。
b
- 设置
dragEnabled
属性的值
HeadlessException
- 如果
b
是
true
和
GraphicsEnvironment.isHeadless()
返回
true
GraphicsEnvironment.isHeadless()
, getDragEnabled()
, JComponent.setTransferHandler(javax.swing.TransferHandler)
, TransferHandler
public boolean getDragEnabled()
dragEnabled
属性的值。
dragEnabled
属性
setDragEnabled(boolean)
public void setPreviewPanel(JComponent preview)
PropertyChangeEvent
一个PropertyChangeEvent
。
preview
- 显示当前颜色的
JComponent
Container.addPropertyChangeListener(java.beans.PropertyChangeListener)
public JComponent getPreviewPanel()
JComponent
对象 - 预览面板
public void addChooserPanel(AbstractColorChooserPanel panel)
panel
- 要加入的
AbstractColorChooserPanel
public AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel panel)
panel
- 一个指定要删除的面板的字符串
IllegalArgumentException
- 如果面板不在已知选择器面板的列表中
public void setChooserPanels(AbstractColorChooserPanel[] panels)
panels
- 一个
AbstractColorChooserPanel
对象的数组
public AbstractColorChooserPanel[] getChooserPanels()
AbstractColorChooserPanel
对象
public ColorSelectionModel getSelectionModel()
ColorSelectionModel
对象
public void setSelectionModel(ColorSelectionModel newModel)
newModel
- 新的
ColorSelectionModel
对象
protected String paramString()
JColorChooser
的字符串表示JColorChooser
。
该方法仅用于调试目的,并且返回的字符串的内容和格式可能因实现而异。
返回的字符串可能为空,但可能不是null
。
paramString
在
JComponent
JColorChooser
的字符串表示
JColorChooser
public AccessibleContext getAccessibleContext()
getAccessibleContext
在界面
Accessible
getAccessibleContext
在
Component
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.