SingleSelectionModel (JavaFX 25)
Description: declaration: module: jfx.incubator.richtext, package: jfx.incubator.scene.control.richtext, class: SingleSelectionModel

# Class SingleSelectionModel

java.lang.Object
jfx.incubator.scene.control.richtext.SingleSelectionModel

All Implemented Interfaces:
  `SelectionModel`

public final class SingleSelectionModel extends Object implements SelectionModel
This `SelectionModel` supports a single selection segment.

Since:
  24

- ## Property Summary

  Properties
  Type
  Property
  Description
  `ReadOnlyProperty<TextPos>`
  `anchorPosition`
  Anchor position property.
  `ReadOnlyProperty<TextPos>`
  `caretPosition`
  Caret position property.
  `ReadOnlyProperty<SelectionSegment>`
  `selection`
  Selection property.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SingleSelectionModel()`
  The constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ReadOnlyProperty<TextPos>`
  `anchorPositionProperty()`
  Anchor position property.
  `ReadOnlyProperty<TextPos>`
  `caretPositionProperty()`
  Caret position property.
  `void`
  `clear()`
  Clears the selection.
  `void`
  `extendSelection(StyledTextModel model, TextPos pos)`
  Extends selection to the specified position.
  `SelectionSegment`
  `getSelection()`
  Gets the value of the `selection` property.
  `ReadOnlyProperty<SelectionSegment>`
  `selectionProperty()`
  Selection property.
  `void`
  `setSelection(StyledTextModel model, TextPos anchor, TextPos caret)`
  Replaced existing selection, if any, with the new one.

  ### Methods declared in class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Property Details

  - ### anchorPosition

    public ReadOnlyProperty<TextPos> anchorPositionProperty
    Specified by:
      `anchorPositionProperty` in interface `SelectionModel`
    Returns:
      the anchor position property
    See Also:
      - `anchorPositionProperty()`

  - ### caretPosition

    public ReadOnlyProperty<TextPos> caretPositionProperty
    Specified by:
      `caretPositionProperty` in interface `SelectionModel`
    Returns:
      the caret position property
    See Also:
      - `caretPositionProperty()`

  - ### selection

    public ReadOnlyProperty<SelectionSegment> selectionProperty
    Specified by:
      `selectionProperty` in interface `SelectionModel`
    Returns:
      the selection property
    See Also:
      - `getSelection()`
      - `selectionProperty()`

- ## Constructor Details

  - ### SingleSelectionModel

    public SingleSelectionModel()
    The constructor.

- ## Method Details

  - ### clear

    public void clear()
    Description copied from interface: `SelectionModel`
    Clears the selection. This sets `selectionProperty`, `anchorPositionProperty`, and `caretPositionProperty` to null.
    Specified by:
      `clear` in interface `SelectionModel`

  - ### setSelection

    public void setSelection(StyledTextModel model, TextPos anchor, TextPos caret)
    Description copied from interface: `SelectionModel`
    Replaced existing selection, if any, with the new one. While this method will accept the text positions outside of the document range, the actual values of `anchorPositionProperty`, and `caretPositionProperty` must always remain within the valid range for the document.
    Specified by:
      `setSelection` in interface `SelectionModel`
    Parameters:
      `model` - the model, must be non-null
      `anchor` - the anchor position, must be non-null
      `caret` - the caret position, must be non-null

  - ### extendSelection

    public void extendSelection(StyledTextModel model, TextPos pos)
    Description copied from interface: `SelectionModel`
    Extends selection to the specified position. Internally, the position will be normalized to be within the document boundaries. This method will issue a `setSelection(model, pos, pos)` call if the model instance is different from that passed before.

    While this method will accept the text position outside of the document range, the actual values of `anchorPositionProperty`, and `caretPositionProperty` must always remain within the valid range for the document.

    Specified by:
      `extendSelection` in interface `SelectionModel`
    Parameters:
      `model` - the model, must be non-null
      `pos` - the new caret position, must be non-null

  - ### anchorPositionProperty

    public ReadOnlyProperty<TextPos> anchorPositionProperty()
    Description copied from interface: `SelectionModel`
    Anchor position property. The value can be null, indicating no selection. When the anchor position is `null`, the `selectionProperty` and the `caretPositionProperty` are also `null`.

    Note: `SelectionModel.selectionProperty()`, `SelectionModel.anchorPositionProperty()`, and `SelectionModel.caretPositionProperty()` are logically connected. When a change occurs, the anchor position is updated first, followed by the caret position, followed by the selection segment.

    Specified by:
      `anchorPositionProperty` in interface `SelectionModel`
    Returns:
      the `anchorPosition` property

  - ### caretPositionProperty

    public ReadOnlyProperty<TextPos> caretPositionProperty()
    Description copied from interface: `SelectionModel`
    Caret position property. The value can be null, indicating no selection. When the caret position is `null`, the `selectionProperty` and the `anchorPositionProperty` are also `null`.

    Note: `SelectionModel.selectionProperty()`, `SelectionModel.anchorPositionProperty()`, and `SelectionModel.caretPositionProperty()` are logically connected. When a change occurs, the anchor position is updated first, followed by the caret position, followed by the selection segment.

    Specified by:
      `caretPositionProperty` in interface `SelectionModel`
    Returns:
      the `caretPosition` property

  - ### selectionProperty

    public ReadOnlyProperty<SelectionSegment> selectionProperty()
    Description copied from interface: `SelectionModel`
    Selection property. The value can be null, indicating no selection. When the selection segment is `null`, the `anchorPositionProperty` and the `caretPositionProperty` are also `null`.
    Specified by:
      `selectionProperty` in interface `SelectionModel`
    Returns:
      the `selection` property
    See Also:
      - `getSelection()`

  - ### getSelection

    public SelectionSegment getSelection()
    Gets the value of the `selection` property.
    Specified by:
      `getSelection` in interface `SelectionModel`
    Property description:
    Returns:
      the value of the `selection` property
    See Also:
      - `selectionProperty()`