Package javafx.scene.control
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.
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:
-
SelectionModel
MultipleSelectionModel
SelectionMode
-
Property Summary
Properties inherited from class javafx.scene.control.SelectionModel
selectedIndex, selectedItem
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clearAndSelect
(int index) In the SingleSelectionModel, this method is functionally equivalent to callingselect(index)
, as only one selection is allowed at a time.void
Clears the selection model of all selected indices.void
clearSelection
(int index) Clears the selection of the given index, if it is currently selected.protected abstract int
Gets the number of items available for the selection model.protected abstract T
getModelItem
(int index) Gets the data model item associated with a specific index.boolean
isEmpty()
This method is available to test whether there are any selected indices/items.boolean
isSelected
(int index) This method will return true if the given index is the currently selected index in this SingleSelectionModel..void
select
(int index) Selects the given index.void
Selects the index for the first instance of given object in the underlying data model.void
Selects the first index.void
Selects the last index.void
Selects the next index.void
Selects the previous index.Methods inherited from class javafx.scene.control.SelectionModel
getSelectedIndex, getSelectedItem, selectedIndexProperty, selectedItemProperty, setSelectedIndex, setSelectedItem
-
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 classSelectionModel<T>
-
clearSelection
public void clearSelection(int index) Clears the selection of the given index, if it is currently selected.- Specified by:
clearSelection
in classSelectionModel<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 classSelectionModel<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 classSelectionModel<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 callingselect(index)
, as only one selection is allowed at a time.- Specified by:
clearAndSelect
in classSelectionModel<T>
- Parameters:
index
- The index that should be the only selected index in this selection model.
-
select
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 classSelectionModel<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 classSelectionModel<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 classSelectionModel<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 classSelectionModel<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 classSelectionModel<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 classSelectionModel<T>
-
getModelItem
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.
-