所有类


javax.swing
类 JColorChooser

java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 javax.swing.JComponent
              继承者 javax.swing.JColorChooser
所有已实现的接口:
ImageObserver, MenuContainer, Serializable, Accessible

public class JColorChooser
   
   
   
   
   
extends JComponent
implements Accessible

JColorChooser 提供一个用于允许用户操作和选择颜色的控制器窗格。有关使用颜色选取器的信息,请参阅《The Java Tutorial》中的 How to Use Color Choosers 一节。

此类提供三个级别的 API:

  1. 显示有模式颜色选取器对话框并返回用户所选颜色的静态便捷方法。
  2. 创建颜色选取器对话框的静态便捷方法,可以指定当用户按下其中一个对话框按钮时要调用的 ActionListener
  3. (在任何容器中)直接创建 JColorChooser 窗格实例的能力。可以添加 PropertyChange 侦听器以检测何时当前“颜色”属性发生更改。

警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder


嵌套类摘要
protected  class JColorChooser.AccessibleJColorChooser
          此类实现对 JColorChooser 类的可访问性支持。
 
从类 javax.swing.JComponent 继承的嵌套类/接口
JComponent.AccessibleJComponent
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
protected  AccessibleContext accessibleContext
           
static String CHOOSER_PANELS_PROPERTY
          chooserPanel 数组属性名。
static String PREVIEW_PANEL_PROPERTY
          预览面板属性名。
static String SELECTION_MODEL_PROPERTY
          选择模型属性名。
 
从类 javax.swing.JComponent 继承的字段
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
从类 java.awt.Component 继承的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
JColorChooser()
          创建初始颜色为白色的颜色选取器窗格。
JColorChooser(Color initialColor)
          创建具有指定初始颜色的颜色选取器窗格。
JColorChooser(ColorSelectionModel model)
          创建具有指定 ColorSelectionModel 颜色选取器窗格。
 
方法摘要
 void addChooserPanel(AbstractColorChooserPanel panel)
          将颜色选取器面板添加到颜色选取器。
static JDialog createDialog(Component c, String title, boolean modal, JColorChooser chooserPane, ActionListener okListener, ActionListener cancelListener)
          创建并返回包含指定 ColorChooser 窗格及 "OK"、"Cancel"、"Reset" 按钮的新对话框。
 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 的字符串表示形式。
 AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel panel)
          移除指定的 Color Panel。
 void setChooserPanels(AbstractColorChooserPanel[] panels)
          指定用于选取颜色值的 Color Panel。
 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 已更改的通知。
 
从类 javax.swing.JComponent 继承的方法
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, 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
 
从类 java.awt.Container 继承的方法
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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
从类 java.awt.Component 继承的方法
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, hide, 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, transferFocusUpCycle
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

SELECTION_MODEL_PROPERTY

public static final String SELECTION_MODEL_PROPERTY
选择模型属性名。

另请参见:
常量字段值

PREVIEW_PANEL_PROPERTY

public static final String PREVIEW_PANEL_PROPERTY
预览面板属性名。

另请参见:
常量字段值

CHOOSER_PANELS_PROPERTY

public static final String CHOOSER_PANELS_PROPERTY
chooserPanel 数组属性名。

另请参见:
常量字段值

accessibleContext

protected AccessibleContext accessibleContext
构造方法详细信息

JColorChooser

public JColorChooser()
创建初始颜色为白色的颜色选取器窗格。


JColorChooser

public JColorChooser(Color initialColor)
创建具有指定初始颜色的颜色选取器窗格。

参数:
initialColor - 选取器中的初始颜色设置

JColorChooser

public JColorChooser(ColorSelectionModel model)
创建具有指定 ColorSelectionModel 颜色选取器窗格。

参数:
model - 要使用的 ColorSelectionModel
方法详细信息

showDialog

public static Color showDialog(Component component,
                               String title,
                               Color initialColor)
                        throws HeadlessException
显示有模式的颜色选取器,在隐藏对话框之前一直阻塞。如果用户按下 "OK" 按钮,则此方法隐藏/释放对话框并返回所选颜色。如果用户按下 "Cancel" 按钮或者在没有按 "OK" 的情况下关闭对话框,则此方法隐藏/释放对话框并返回 null

参数:
component - 对话框的父 Component
title - 包含对话框标题的 String
initialColor - 显示颜色选取器时的初始 Color 设置
返回:
所选颜色;如果用户退出,则返回 null
抛出:
HeadlessException - 如果 GraphicsEnvironment.isHeadless() 返回 true。
另请参见:
GraphicsEnvironment.isHeadless()

createDialog

public static JDialog createDialog(Component c,
                                   String title,
                                   boolean modal,
                                   JColorChooser chooserPane,
                                   ActionListener okListener,
                                   ActionListener cancelListener)
                            throws HeadlessException
创建并返回包含指定 ColorChooser 窗格及 "OK"、"Cancel"、"Reset" 按钮的新对话框。如果按下 "OK" 或 "Cancel" 按钮,则对话框自动隐藏(但未释放)。如果按下 "Reset" 按钮,则将颜色选取器的颜色重置为上一次在对话框上调用 show 时设置的颜色,并且对话框仍然显示。

参数:
c - 对话框的父组件
title - 对话框的标题
modal - 布尔值为 true 时,在关闭对话框之前,程序的剩余部分将一直处于非激活状态。
chooserPane - 要置于对话框中的颜色选取器
okListener - 按下 "OK" 时调用的 ActionListener
cancelListener - 按下 "Cancel" 时调用的 ActionListener
返回:
包含颜色选取器窗格的新对话框
抛出:
HeadlessException - 如果 GraphicsEnvironment.isHeadless() 返回 true。
另请参见:
GraphicsEnvironment.isHeadless()

微信小程序

微信扫一扫体验

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部