- All Implemented Interfaces:
javafx.css.Styleable,javafx.event.EventTarget
SelectableTextFlow class extends the functionality of the regular TextFlow
by providing the ability to select a range of text. The selected range is visually highlighted
and can be retrieved as a string using getSelectedRangeAsString().
Similar to the regular TextFlow, the SelectableTextFlow can contain any type of
nodes; however, for the purpose of text selection, it is recommended to limit the children to
Text nodes exclusively. It is important to note that each child Text
must accurately report its length, which may not be the case for emojis and font icons.
-
Nested Class Summary
Nested Classes -
Property Summary
PropertiesTypePropertyDescriptionfinal javafx.beans.property.SimpleObjectProperty<javafx.scene.control.ContextMenu> Specifies theContextMenuassociated with this component.final javafx.beans.property.ObjectProperty<javafx.scene.paint.Paint> Specifies the color used for the font (foreground) of selected text.final javafx.beans.property.BooleanPropertyAllows text selection by double-clicking on any word.Defines the word boundaries for text selection when double-clicking.Properties inherited from class javafx.scene.text.TextFlow
lineSpacing, tabSize, textAlignmentProperties inherited from class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, widthProperties inherited from class javafx.scene.Parent
needsLayoutProperties 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, focusVisible, focusWithin, 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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final javafx.beans.property.SimpleObjectProperty<javafx.scene.control.ContextMenu> protected final javafx.beans.property.ObjectProperty<javafx.scene.paint.Paint> protected intprotected final SelectableTextFlow.SelectionFields inherited from class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZEFields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT -
Constructor Summary
ConstructorsConstructorDescriptionSelectableTextFlow(@Nullable javafx.scene.text.Text... children) Creates a new instance ofSelectableTextFlowwith the specified childTextelements. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all the text content from the TextFlow by removing all its children.voidRemoves the current text selection.final javafx.beans.property.SimpleObjectProperty<javafx.scene.control.ContextMenu> Specifies theContextMenuassociated with this component.voidCopies the currently selected text range to the clipboard.protected @Nullable RangefindWord(int charIndex) static List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>> protected StringBuilderReturns the content of the TextFlow as a string representation.protected intjavafx.scene.control.ContextMenuGets the value of thecontextMenuproperty.List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>> javafx.scene.paint.PaintGets the value of thehighlightTextFillproperty.protected javafx.scene.text.HitInfogetHitInfo(javafx.scene.input.MouseEvent e) Retrieves the currently selected text range as a string.booleanGets the value of thetextSelectionOnMouseClickproperty.Gets the value of thewordBoundaryPredicateproperty.final javafx.beans.property.ObjectProperty<javafx.scene.paint.Paint> Specifies the color used for the font (foreground) of selected text.protected voidvoidSelects all text content.voidselectRange(int fromInclusive, int toExclusive) Selects a range of text content from the specified indices.voidsetContextMenu(@Nullable javafx.scene.control.ContextMenu contextMenu) Sets the value of thecontextMenuproperty.voidsetHighlightTextFill(javafx.scene.paint.Paint value) Sets the value of thehighlightTextFillproperty.protected voidvoidsetText(javafx.scene.text.Text... children) Sets the text content of the TextFlow by replacing its children with the specified Text nodes.voidsetTextSelectionOnMouseClick(boolean textSelectionOnMouseClick) Sets the value of thetextSelectionOnMouseClickproperty.voidsetWordBoundaryPredicate(@Nullable Predicate<Character> wordBoundaryPredicate) Sets the value of thewordBoundaryPredicateproperty.protected voidshowContextMenu(javafx.scene.input.MouseEvent e) final javafx.beans.property.BooleanPropertyAllows text selection by double-clicking on any word.Defines the word boundaries for text selection when double-clicking.Methods inherited from class javafx.scene.text.TextFlow
caretShape, computeMinHeight, computePrefHeight, computePrefWidth, getBaselineOffset, getContentBias, getLineSpacing, getTabSize, getTextAlignment, hitTest, layoutChildren, lineSpacingProperty, queryAccessibleAttribute, rangeShape, requestLayout, setLineSpacing, setTabSize, setTextAlignment, setWidth, tabSizeProperty, textAlignmentProperty, underlineShape, usesMirroringMethods inherited from class javafx.scene.layout.Pane
getChildrenMethods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computeMaxHeight, computeMaxWidth, computeMinWidth, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isResizable, 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, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthPropertyMethods inherited from class javafx.scene.Parent
getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestParentLayout, setNeedsLayout, updateBoundsMethods 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, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, 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, isFocusVisible, isFocusWithin, 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, viewOrderProperty, visiblePropertyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javafx.css.Styleable
getStyleableNode
-
Property Details
-
contextMenu
public final javafx.beans.property.SimpleObjectProperty<javafx.scene.control.ContextMenu> contextMenuPropertySpecifies theContextMenuassociated with this component.The context menu provides a set of options that can be displayed when the user right-clicks on the component.
- See Also:
-
highlightTextFill
public final javafx.beans.property.ObjectProperty<javafx.scene.paint.Paint> highlightTextFillPropertySpecifies the color used for the font (foreground) of selected text.Only applies to the first node in a TextFlow. For more details, see JDK-8149134.
- See Also:
-
wordBoundaryPredicate
public final javafx.beans.property.SimpleObjectProperty<Predicate<Character>> wordBoundaryPredicatePropertyDefines the word boundaries for text selection when double-clicking. See alsotextSelectionOnMouseClickProperty().- See Also:
-
textSelectionOnMouseClick
public final javafx.beans.property.BooleanProperty textSelectionOnMouseClickPropertyAllows text selection by double-clicking on any word.Default is
false.- See Also:
-
-
Field Details
-
WORD_BOUNDARY_PREDICATE
-
selection
-
mouseDragStartPos
protected int mouseDragStartPos -
contextMenuProperty
protected final javafx.beans.property.SimpleObjectProperty<javafx.scene.control.ContextMenu> contextMenuProperty -
highlightTextFill
protected final javafx.beans.property.ObjectProperty<javafx.scene.paint.Paint> highlightTextFill -
wordBoundaryPredicate
-
-
Constructor Details
-
SelectableTextFlow
public SelectableTextFlow() -
SelectableTextFlow
public SelectableTextFlow(@Nullable @Nullable javafx.scene.text.Text... children) Creates a new instance ofSelectableTextFlowwith the specified childTextelements.- Parameters:
children- the childTextelements to be added to the flow, or null for no children
-
-
Method Details
-
contextMenuProperty
public final javafx.beans.property.SimpleObjectProperty<javafx.scene.control.ContextMenu> contextMenuProperty()Specifies theContextMenuassociated with this component.The context menu provides a set of options that can be displayed when the user right-clicks on the component.
- Returns:
- the
contextMenuproperty - See Also:
-
getContextMenu
public javafx.scene.control.ContextMenu getContextMenu()Gets the value of thecontextMenuproperty.- Property description:
- Specifies the
ContextMenuassociated with this component.The context menu provides a set of options that can be displayed when the user right-clicks on the component.
- Returns:
- the value of the
contextMenuproperty - See Also:
-
setContextMenu
public void setContextMenu(@Nullable @Nullable javafx.scene.control.ContextMenu contextMenu) Sets the value of thecontextMenuproperty.- Property description:
- Specifies the
ContextMenuassociated with this component.The context menu provides a set of options that can be displayed when the user right-clicks on the component.
- Parameters:
contextMenu- the value for thecontextMenuproperty- See Also:
-
highlightTextFillProperty
public final javafx.beans.property.ObjectProperty<javafx.scene.paint.Paint> highlightTextFillProperty()Specifies the color used for the font (foreground) of selected text.Only applies to the first node in a TextFlow. For more details, see JDK-8149134.
- Returns:
- the
highlightTextFillproperty - See Also:
-
getHighlightTextFill
public javafx.scene.paint.Paint getHighlightTextFill()Gets the value of thehighlightTextFillproperty.- Property description:
- Specifies the color used for the font (foreground) of selected text.
Only applies to the first node in a TextFlow. For more details, see JDK-8149134.
- Returns:
- the value of the
highlightTextFillproperty - See Also:
-
setHighlightTextFill
public void setHighlightTextFill(javafx.scene.paint.Paint value) Sets the value of thehighlightTextFillproperty.- Property description:
- Specifies the color used for the font (foreground) of selected text.
Only applies to the first node in a TextFlow. For more details, see JDK-8149134.
- Parameters:
value- the value for thehighlightTextFillproperty- See Also:
-
wordBoundaryPredicateProperty
public final javafx.beans.property.SimpleObjectProperty<Predicate<Character>> wordBoundaryPredicateProperty()Defines the word boundaries for text selection when double-clicking. See alsotextSelectionOnMouseClickProperty().- Returns:
- the
wordBoundaryPredicateproperty - See Also:
-
getWordBoundaryPredicate
Gets the value of thewordBoundaryPredicateproperty.- Property description:
- Defines the word boundaries for text selection when double-clicking.
See also
textSelectionOnMouseClickProperty(). - Returns:
- the value of the
wordBoundaryPredicateproperty - See Also:
-
setWordBoundaryPredicate
public void setWordBoundaryPredicate(@Nullable @Nullable Predicate<Character> wordBoundaryPredicate) Sets the value of thewordBoundaryPredicateproperty.- Property description:
- Defines the word boundaries for text selection when double-clicking.
See also
textSelectionOnMouseClickProperty(). - Parameters:
wordBoundaryPredicate- the value for thewordBoundaryPredicateproperty- See Also:
-
textSelectionOnMouseClickProperty
public final javafx.beans.property.BooleanProperty textSelectionOnMouseClickProperty()Allows text selection by double-clicking on any word.Default is
false.- Returns:
- the
textSelectionOnMouseClickproperty - See Also:
-
getTextSelectionOnMouseClick
public boolean getTextSelectionOnMouseClick()Gets the value of thetextSelectionOnMouseClickproperty.- Property description:
- Allows text selection by double-clicking on any word.
Default is
false. - Returns:
- the value of the
textSelectionOnMouseClickproperty - See Also:
-
setTextSelectionOnMouseClick
public void setTextSelectionOnMouseClick(boolean textSelectionOnMouseClick) Sets the value of thetextSelectionOnMouseClickproperty.- Property description:
- Allows text selection by double-clicking on any word.
Default is
false. - Parameters:
textSelectionOnMouseClick- the value for thetextSelectionOnMouseClickproperty- See Also:
-
setText
public void setText(javafx.scene.text.Text... children) Sets the text content of the TextFlow by replacing its children with the specified Text nodes. -
clear
public void clear()Clears all the text content from the TextFlow by removing all its children. -
getContentAsString
Returns the content of the TextFlow as a string representation. -
getSelectedRangeAsString
Retrieves the currently selected text range as a string. -
selectAll
public void selectAll()Selects all text content. -
selectRange
public void selectRange(int fromInclusive, int toExclusive) Selects a range of text content from the specified indices.- Parameters:
fromInclusive- the starting index, inclusivetoExclusive- the ending index, exclusive
-
clearSelection
public void clearSelection()Removes the current text selection. -
copySelectedRangeToClipboard
public void copySelectedRangeToClipboard()Copies the currently selected text range to the clipboard. -
initListeners
protected void initListeners() -
getHitInfo
protected javafx.scene.text.HitInfo getHitInfo(javafx.scene.input.MouseEvent e) -
setSelectionPath
protected void setSelectionPath() -
getContent
-
getContentLength
protected int getContentLength() -
showContextMenu
protected void showContextMenu(javafx.scene.input.MouseEvent e) -
findWord
-
getClassCssMetaData
-
getCssMetaData
- Specified by:
getCssMetaDatain interfacejavafx.css.Styleable- Overrides:
getCssMetaDatain classjavafx.scene.text.TextFlow
-