- java.lang.Object
-
- javafx.scene.Node
-
- javafx.scene.Parent
-
- javafx.scene.layout.Region
-
- javafx.scene.control.Control
-
- javafx.scene.control.Labeled
-
- javafx.scene.control.Cell<T>
-
- javafx.scene.control.IndexedCell<T>
-
- javafx.scene.control.ListCell<T>
-
- javafx.scene.control.cell.CheckBoxListCell<T>
-
- 参数类型
-
T
- ListView中包含的元素的类型。
- All Implemented Interfaces:
-
Styleable
,EventTarget
,Skinnable
public class CheckBoxListCell<T> extends ListCell<T>
一个包含一个ListCell
实现的类,它在单元格中绘制一个CheckBox
节点,可选地带有一个标签来指示复选框代表什么。CheckBoxListCell使用
ListView
左侧的CheckBox进行呈现,并且与列表项相关的文本占用所有剩余的水平空间。要构造这个类的实例,有必要提供一个
Callback
,给定一个类型T的对象将返回一个ObservableValue<Boolean>
,表示给定的项是否被选择。 这个ObservableValue将双向绑定(这意味着单元格中的复选框将基于用户交互设置/取消设置此属性,而复选框将反映ObservableValue<Boolean>
的状态,如果外部更改)。请注意,CheckBoxListCell渲染CheckBox“live”,这意味着CheckBox始终是交互式的,可以直接由用户切换。 这意味着单元格不需要输入其
editing state
(通常由用户双击单元格)。 这方面的一个副作用是,通常的编辑回调(如on edit commit
)将不被调用。 如果要通知更改,建议直接观察CheckBox操作的布尔属性。
-
-
Property Summary
Properties Type Property 描述 ObjectProperty<StringConverter<T>>
converter
ObjectProperty<Callback<T,ObservableValue<Boolean>>>
selectedStateCallback
属性表示由屏幕上显示的复选框绑定的Callback
。-
Properties inherited from class javafx.scene.control.Control
contextMenu, skin, tooltip
-
Properties inherited from class javafx.scene.control.IndexedCell
index
-
Properties inherited from class javafx.scene.control.Labeled
alignment, contentDisplay, ellipsisString, font, graphic, graphicTextGap, labelPadding, lineSpacing, mnemonicParsing, textAlignment, textFill, textOverrun, text, underline, wrapText
-
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 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 描述 CheckBoxListCell()
创建一个默认的CheckBoxListCell。CheckBoxListCell(Callback<T,ObservableValue<Boolean>> getSelectedProperty)
创建一个默认的CheckBoxListCell。CheckBoxListCell(Callback<T,ObservableValue<Boolean>> getSelectedProperty, StringConverter<T> converter)
用自定义字符串转换器创建一个CheckBoxListCell。
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 ObjectProperty<StringConverter<T>>
converterProperty()
static <T> Callback<ListView<T>,ListCell<T>>
forListView(Callback<T,ObservableValue<Boolean>> getSelectedProperty)
创建用于ListView控件的单元格工厂。static <T> Callback<ListView<T>,ListCell<T>>
forListView(Callback<T,ObservableValue<Boolean>> getSelectedProperty, StringConverter<T> converter)
创建用于ListView控件的单元格工厂。StringConverter<T>
getConverter()
返回此单元格中使用的StringConverter
。Callback<T,ObservableValue<Boolean>>
getSelectedStateCallback()
返回由屏幕上显示的复选框绑定的Callback
。ObjectProperty<Callback<T,ObservableValue<Boolean>>>
selectedStateCallbackProperty()
属性表示由屏幕上显示的复选框绑定的Callback
。void
setConverter(StringConverter<T> value)
设置要在此单元格中使用的StringConverter
。void
setSelectedStateCallback(Callback<T,ObservableValue<Boolean>> value)
设置由屏幕上显示的复选框绑定的Callback
。void
updateItem(T item, boolean empty)
updateItem方法不应该被开发人员调用,但它是开发人员覆盖的最佳方式,以允许它们自定义单元格的视觉效果。-
Methods inherited from class javafx.scene.control.Cell
editableProperty, editingProperty, emptyProperty, getInitialFocusTraversable, getItem, isEditable, isEditing, isEmpty, isItemChanged, isSelected, itemProperty, layoutChildren, selectedProperty, setEditable, setItem, updateSelected
-
Methods inherited from class javafx.scene.control.Control
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getCssMetaData, getSkin, getTooltip, isResizable, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty
-
Methods inherited from class javafx.scene.control.IndexedCell
getIndex, indexProperty, updateIndex
-
Methods inherited from class javafx.scene.control.Labeled
alignmentProperty, contentDisplayProperty, ellipsisStringProperty, fontProperty, getAlignment, getClassCssMetaData, getContentBias, getContentDisplay, getControlCssMetaData, getEllipsisString, getFont, getGraphic, getGraphicTextGap, getInitialAlignment, getLabelPadding, getLineSpacing, getText, getTextAlignment, getTextFill, getTextOverrun, graphicProperty, graphicTextGapProperty, isMnemonicParsing, isUnderline, isWrapText, labelPaddingProperty, lineSpacingProperty, mnemonicParsingProperty, setAlignment, setContentDisplay, setEllipsisString, setFont, setGraphic, setGraphicTextGap, setLineSpacing, setMnemonicParsing, setText, setTextAlignment, setTextFill, setTextOverrun, setUnderline, setWrapText, textAlignmentProperty, textFillProperty, textOverrunProperty, textProperty, toString, underlineProperty, wrapTextProperty
-
Methods inherited from class javafx.scene.control.ListCell
cancelEdit, commitEdit, createDefaultSkin, executeAccessibleAction, getListView, listViewProperty, queryAccessibleAttribute, startEdit, updateListView
-
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, 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, 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
-
-
-
-
Property Detail
-
converter
public final ObjectProperty<StringConverter<T>> converterProperty
- 结果
-
StringConverter
属性
-
selectedStateCallback
public final ObjectProperty<Callback<T,ObservableValue<Boolean>>> selectedStateCallbackProperty
属性表示由屏幕上显示的复选框绑定的Callback
。
-
-
构造方法详细信息
-
CheckBoxListCell
public CheckBoxListCell()
创建一个默认的CheckBoxListCell。
-
CheckBoxListCell
public CheckBoxListCell(Callback<T,ObservableValue<Boolean>> getSelectedProperty)
创建一个默认的CheckBoxListCell。- 参数
-
getSelectedProperty
- ACallback
将从ListView中返回一个ObservableValue<Boolean>
给定一个项目。
-
CheckBoxListCell
public CheckBoxListCell(Callback<T,ObservableValue<Boolean>> getSelectedProperty, StringConverter<T> converter)
用自定义字符串转换器创建一个CheckBoxListCell。- 参数
-
getSelectedProperty
- ACallback
,将从ListView中返回一个ObservableValue<Boolean>
项目。 -
converter
- 给定类型为T的对象的StringConverter将返回一个可以用于可视化表示对象的字符串。
-
-
方法详细信息
-
forListView
public static <T> Callback<ListView<T>,ListCell<T>> forListView(Callback<T,ObservableValue<Boolean>> getSelectedProperty)
创建用于ListView控件的单元格工厂。 当在ListView中使用时,CheckBoxListCell
将使用ListView左侧的“复选框”进行呈现,与列表项相关的文本占用所有剩余的水平空间。
-
forListView
public static <T> Callback<ListView<T>,ListCell<T>> forListView(Callback<T,ObservableValue<Boolean>> getSelectedProperty, StringConverter<T> converter)
创建用于ListView控件的单元格工厂。 当在ListView中使用时,CheckBoxListCell
将使用ListView左侧的复选框进行渲染,其中与列表项相关的文本占用所有剩余的水平空间。- 参数类型
-
T
- ListView中包含的元素的类型。 - 参数
-
getSelectedProperty
- ACallback
,给定一个类型T(这是从ListView<T>.items
列表中取出的值)的对象,将返回一个表示给定项目是否被选择的ObservableValue<Boolean>
。 这个ObservableValue将双向绑定(这意味着单元格中的CheckBox将根据用户交互设置/取消设置此属性,如果外部改变,CheckBox将反映ObservableValue的状态)。 -
converter
- 提供类型为T的对象的StringConverter将返回一个可以用于可视化表示对象的字符串。 - 结果
-
A
Callback
将返回能够处理ListView中包含的元素类型的ListCell。
-
converterProperty
public final ObjectProperty<StringConverter<T>> converterProperty()
- 结果
-
StringConverter
属性
-
setConverter
public final void setConverter(StringConverter<T> value)
设置要在此单元格中使用的StringConverter
。- 参数
-
value
-StringConverter
-
getConverter
public final StringConverter<T> getConverter()
返回此单元格中使用的StringConverter
。- 结果
-
在这个单元格中使用的
StringConverter
-
selectedStateCallbackProperty
public final ObjectProperty<Callback<T,ObservableValue<Boolean>>> selectedStateCallbackProperty()
属性表示由屏幕上显示的复选框绑定的Callback
。
-
setSelectedStateCallback
public final void setSelectedStateCallback(Callback<T,ObservableValue<Boolean>> value)
设置由屏幕上显示的复选框绑定的Callback
。- 参数
-
value
-Callback
-
getSelectedStateCallback
public final Callback<T,ObservableValue<Boolean>> getSelectedStateCallback()
返回由屏幕上显示的复选框绑定的Callback
。- 结果
-
由屏幕上显示的复选框绑定的
Callback
-
updateItem
public void updateItem(T item, boolean empty)
updateItem方法不应该被开发人员调用,但它是开发人员覆盖的最佳方式,以允许它们自定义单元格的视觉效果。 为了澄清,开发人员不应该在他们的代码中调用这个方法(他们应该留给UI控件,如ListView
控件)来调用这个方法。 但是,使用updateItem方法的目的是使开发人员在指定自定义单元工厂时(再次像ListViewcell factory
),可以覆盖updateItem方法以允许对单元格进行完全自定义。非常重要的是,Cell的子类会正确覆盖updateItem方法,因为这样做会导致诸如空白单元格或其中出现意外内容的单元格等问题。 以下是如何正确覆盖updateItem方法的示例:
protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); if (empty || item == null) { setText(null); setGraphic(null); } else { setText(item.toString()); } }
注意在这段代码示例中的两个重点:
- 我们称之为super.updateItem(T,boolean)方法。 如果没有这样做,项目和空属性设置不正确,您可能会遇到图形问题。
- 我们测试
empty
条件,如果为true,我们将文本和图形属性设置为null。 如果我们不这样做,几乎可以保证最终用户意外地看到细胞中的图形工件。
- 重写:
-
updateItem
在Cell<T>
- 参数
-
item
- 单元格的新项目。 -
empty
- 该单元格是否表示列表中的数据。 如果它是空的,那么它不表示任何域数据,而是用于呈现“空”行的单元格。
-
-