- java.lang.Object
-
- javafx.scene.Node
-
- javafx.scene.Parent
-
- javafx.scene.layout.Region
-
- javafx.scene.control.Control
-
- javafx.scene.control.ComboBoxBase<Color>
-
- javafx.scene.control.ColorPicker
-
- All Implemented Interfaces:
-
Styleable
,EventTarget
,Skinnable
public class ColorPicker extends ComboBoxBase<Color>
ColorPicker控件允许用户从标准的颜色调色板中选择一种颜色,只需点击一下简单的选择或定义自己的自定义颜色。
value
是当前选择的Color
。 初始颜色可以通过调用setColor或通过构造函数来设置。 如果没有指定,则使用默认的初始颜色。ColorPicker控件提供具有预定义颜色集的调色板。 如果用户不想从预定义的集合中选择,则可以通过与自定义颜色对话框交互来创建自定义颜色。 该对话框提供RGB,HSB和Web的交互模式,以创建新的颜色。 它还允许修改颜色的不透明度。
一旦定义了一种新的颜色,用户可以选择是保存它还是使用它。 如果保存新颜色,则此颜色将显示在调色板上的自定义颜色区域中。 另外
getCustomColors
返回保存的自定义颜色列表。promptText
不支持,因此是无操作的。 但未来可能会得到支持。final ColorPicker colorPicker = new ColorPicker(); colorPicker.setOnAction(new EventHandler() { public void handle(Event t) { Color c = colorPicker.getValue(); System.out.println("New Color's RGB = "+c.getRed()+" "+c.getGreen()+" "+c.getBlue()); } });
ColorPicker控件的外观可以通过三种方式进行设计:简单的按钮模式,MenuButton模式或SplitMenuButton模式。 默认为MenuButton模式。 对于像外观的按钮,使用的样式类是
STYLE_CLASS_BUTTON
,对于SplitMenuButton的外观和行为,使用的样式类是STYLE_CLASS_SPLIT_BUTTON
。colorPicker.getStyleClass().add("button");
colorPicker.getStyleClass().add("split-button");
- 从以下版本开始:
- JavaFX 2.2
-
-
Property Summary
-
Properties inherited from class javafx.scene.control.ComboBoxBase
armed, editable, onAction, onHidden, onHiding, onShowing, onShown, promptText, showing, value
-
Properties inherited from class javafx.scene.control.Control
contextMenu, skin, tooltip
-
Properties inherited from class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
-
Properties inherited from class javafx.scene.Parent
needsLayout
-
Properties inherited from class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
-
-
Field Summary
Fields Modifier and Type Field 描述 static String
STYLE_CLASS_BUTTON
指定一个Button的样式类就像ColorPicker控件的外观。static String
STYLE_CLASS_SPLIT_BUTTON
指定SplitMenuButton的样式类,如ColorPicker控件的外观。-
Fields inherited from class javafx.scene.control.ComboBoxBase
ON_HIDDEN, ON_HIDING, ON_SHOWING, ON_SHOWN
-
Fields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
-
Fields inherited from class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZE
-
-
构造方法摘要
构造方法 Constructor 描述 ColorPicker()
创建默认的ColorPicker实例,将所选颜色设置为白色。ColorPicker(Color color)
创建一个ColorPicker实例,并将所选颜色设置为给定的颜色。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 protected Skin<?>
createDefaultSkin()
为此控件创建一个新的默认皮肤实例。ObservableList<Color>
getCustomColors()
获取用户添加到调色板的自定义颜色列表。-
Methods inherited from class javafx.scene.control.ComboBoxBase
arm, armedProperty, disarm, editableProperty, executeAccessibleAction, getOnAction, getOnHidden, getOnHiding, getOnShowing, getOnShown, getPromptText, getValue, hide, isArmed, isEditable, isShowing, onActionProperty, onHiddenProperty, onHidingProperty, onShowingProperty, onShownProperty, promptTextProperty, queryAccessibleAttribute, setEditable, setOnAction, setOnHidden, setOnHiding, setOnShowing, setOnShown, setPromptText, setValue, show, showingProperty, valueProperty
-
Methods inherited from class javafx.scene.control.Control
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getClassCssMetaData, getContextMenu, getControlCssMetaData, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty
-
Methods inherited from class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from class javafx.scene.Parent
getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
-
Methods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
-
Methods inherited from interface javafx.css.Styleable
getStyleableNode
-
-
-
-
字段详细信息
-
STYLE_CLASS_BUTTON
public static final String STYLE_CLASS_BUTTON
指定一个Button的样式类就像ColorPicker控件的外观。- 另请参见:
- Constant Field Values
-
STYLE_CLASS_SPLIT_BUTTON
public static final String STYLE_CLASS_SPLIT_BUTTON
指定SplitMenuButton的样式类,如ColorPicker控件的外观。- 另请参见:
- Constant Field Values
-
-
构造方法详细信息
-
ColorPicker
public ColorPicker()
创建默认的ColorPicker实例,将所选颜色设置为白色。
-
ColorPicker
public ColorPicker(Color color)
创建一个ColorPicker实例,并将所选颜色设置为给定的颜色。- 参数
-
color
- 要设置为ColorPicker当前选定的颜色。
-
-
方法详细信息
-
getCustomColors
public final ObservableList<Color> getCustomColors()
获取用户添加到调色板的自定义颜色列表。- 结果
- 自定义颜色列表
-
createDefaultSkin
protected Skin<?> createDefaultSkin()
为此控件创建一个新的默认皮肤实例。 如果没有通过CSS-fx-skin
提供皮肤或者在具有setSkin(...)
的子类中显式设置,则调用此控件创建皮肤。- 重写:
-
createDefaultSkin
在Control
- 结果
- 此控件的默认皮肤的新实例。 如果为null,则控件将没有皮肤,除非由css提供。
-
-