Class SingleSelectionModel<T>

java.lang.Object
javafx.scene.control.SelectionModel<T>
javafx.scene.control.SingleSelectionModel<T>
Type Parameters:
T - The type of the item contained in the control that can be selected.

public abstract class SingleSelectionModel<T> extends SelectionModel<T>
A SelectionModel which enforces the requirement that only a single index be selected at any given time. This class exists for controls that allow for pluggable selection models, but which do not allow for multiple selection. A good example is the ChoiceBox control. Conversely, most other controls (ListView, TreeView, TableView, etc) require MultipleSelectionModel implementations (although MultipleSelectionModel does still allow for single selection to be set via the selectionMode property).
Since:
JavaFX 2.0
See Also:
  • Constructor Details

    • SingleSelectionModel

      public SingleSelectionModel()
      Creates a default SingleSelectionModel instance.
  • Method Details

    • clearSelection

      public void clearSelection()

      Clears the selection model of all selected indices.

      Specified by:
      clearSelection in class SelectionModel<T>
    • clearSelection

      public void clearSelection(int index)
      Clears the selection of the given index, if it is currently selected.
      Specified by:
      clearSelection in class SelectionModel<T>
      Parameters:
      index - The selected item to deselect.
    • isEmpty

      public boolean isEmpty()
      This method is available to test whether there are any selected indices/items. It will return true if there are no selected items, and false if there are.
      Specified by:
      isEmpty in class SelectionModel<T>
      Returns:
      Will return true if there are no selected items, and false if there are.
    • isSelected

      public boolean isSelected(int index)

      This method will return true if the given index is the currently selected index in this SingleSelectionModel..

      Specified by:
      isSelected in class SelectionModel<T>
      Parameters:
      index - The index to check as to whether it is currently selected or not.
      Returns:
      True if the given index is selected, false otherwise.
    • clearAndSelect

      public void clearAndSelect(int index)
      In the SingleSelectionModel, this method is functionally equivalent to calling select(index), as only one selection is allowed at a time.
      Specified by:
      clearAndSelect in class SelectionModel<T>
      Parameters:
      index - The index that should be the only selected index in this selection model.
    • select

      public void select(T obj)
      Selects the index for the first instance of given object in the underlying data model. Since the SingleSelectionModel can only support having a single index selected at a time, this also causes any previously selected index to be unselected.
      Specified by:
      select in class SelectionModel<T>
      Parameters:
      obj - The object to attempt to select in the underlying data model.
    • select

      public void select(int index)
      Selects the given index. Since the SingleSelectionModel can only support having a single index selected at a time, this also causes any previously selected index to be unselected.
      Specified by:
      select in class SelectionModel<T>
      Parameters:
      index - The position of the item to select in the selection model.
    • selectPrevious

      public void selectPrevious()
      Selects the previous index. Since the SingleSelectionModel can only support having a single index selected at a time, this also causes any previously selected index to be unselected.
      Specified by:
      selectPrevious in class SelectionModel<T>
    • selectNext

      public void selectNext()
      Selects the next index. Since the SingleSelectionModel can only support having a single index selected at a time, this also causes any previously selected index to be unselected.
      Specified by:
      selectNext in class SelectionModel<T>
    • selectFirst

      public void selectFirst()
      Selects the first index. Since the SingleSelectionModel can only support having a single index selected at a time, this also causes any previously selected index to be unselected.
      Specified by:
      selectFirst in class SelectionModel<T>
    • selectLast

      public void selectLast()
      Selects the last index. Since the SingleSelectionModel can only support having a single index selected at a time, this also causes any previously selected index to be unselected.
      Specified by:
      selectLast in class SelectionModel<T>
    • getModelItem

      protected abstract T getModelItem(int index)
      Gets the data model item associated with a specific index.
      Parameters:
      index - The position of the item in the underlying data model.
      Returns:
      The item that exists at the given index.
    • getItemCount

      protected abstract int getItemCount()
      Gets the number of items available for the selection model. If the number of items can change dynamically, it is the responsibility of the concrete SingleSelectionModel implementation to ensure that items are selected or unselected as appropriate as the items change.
      Returns:
      A number greater than or equal to 0.