- 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 theChoiceBoxcontrol. Conversely, most other controls (ListView,TreeView,TableView, etc) requireMultipleSelectionModelimplementations (although MultipleSelectionModel does still allow for single selection to be set via theselectionModeproperty).- Since:
- JavaFX 2.0
- See Also:
SelectionModel,MultipleSelectionModel,SelectionMode
-
-
Property Summary
-
Properties inherited from class javafx.scene.control.SelectionModel
selectedIndex, selectedItem
-
-
Constructor Summary
Constructors Constructor Description SingleSelectionModel()Creates a default SingleSelectionModel instance.
-
Method Summary
Modifier and Type Method Description voidclearAndSelect(int index)In the SingleSelectionModel, this method is functionally equivalent to callingselect(index), as only one selection is allowed at a time.voidclearSelection()Clears the selection model of all selected indices.voidclearSelection(int index)Clears the selection of the given index, if it is currently selected.protected abstract intgetItemCount()Gets the number of items available for the selection model.protected abstract TgetModelItem(int index)Gets the data model item associated with a specific index.booleanisEmpty()This method is available to test whether there are any selected indices/items.booleanisSelected(int index)This method will return true if the given index is the currently selected index in this SingleSelectionModel.voidselect(int index)Selects the given index.voidselect(T obj)Selects the index for the first instance of given object in the underlying data model.voidselectFirst()Selects the first index.voidselectLast()Selects the last index.voidselectNext()Selects the next index.voidselectPrevious()Selects the previous index.-
Methods inherited from class javafx.scene.control.SelectionModel
getSelectedIndex, getSelectedItem, selectedIndexProperty, selectedItemProperty, setSelectedIndex, setSelectedItem
-
-
-
-
Method Detail
-
clearSelection
public void clearSelection()
Clears the selection model of all selected indices.
- Specified by:
clearSelectionin classSelectionModel<T>
-
clearSelection
public void clearSelection(int index)
Clears the selection of the given index, if it is currently selected.- Specified by:
clearSelectionin 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:
isEmptyin 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:
isSelectedin 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:
clearAndSelectin classSelectionModel<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:
selectin 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:
selectin 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:
selectPreviousin 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:
selectNextin 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:
selectFirstin 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:
selectLastin classSelectionModel<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.
-
-