# Class FocusModel<T>

java.lang.Object
javafx.scene.control.FocusModel<T>

Type Parameters:
  `T` - the type of the focused item

Direct Known Subclasses:
  `TableFocusModel`

public abstract class FocusModel<T> extends Object
The abstract base class for FocusModel implementations.

Since:
  JavaFX 2.0

- ## Property Summary

  Properties
  Type
  Property
  Description
  `final ReadOnlyIntegerProperty`
  `focusedIndex`
  The index of the current item in the FocusModel which has the focus.
  `final ReadOnlyObjectProperty<T>`
  `focusedItem`
  The current item in the FocusModel which has the focus.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FocusModel()`
  Creates a default FocusModel instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `focus(int index)`
  Causes the item at the given index to receive the focus.
  `final ReadOnlyIntegerProperty`
  `focusedIndexProperty()`
  The index of the current item in the FocusModel which has the focus.
  `final ReadOnlyObjectProperty<T>`
  `focusedItemProperty()`
  The current item in the FocusModel which has the focus.
  `void`
  `focusNext()`
  Attempts to give focus to the row after to the currently focused row.
  `void`
  `focusPrevious()`
  Attempts to give focus to the row previous to the currently focused row.
  `final int`
  `getFocusedIndex()`
  Gets the value of the `focusedIndex` property.
  `final T`
  `getFocusedItem()`
  Gets the value of the `focusedItem` property.
  `protected abstract int`
  `getItemCount()`
  Returns the number of items in the data model that underpins the control.
  `protected abstract T`
  `getModelItem(int index)`
  Returns the item at the given index.
  `boolean`
  `isFocused(int index)`
  Convenience method to inform if the given index is currently focused in this SelectionModel.

  ### Methods declared in class java.lang.Object

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

- ## Property Details

  - ### focusedIndex

    public final ReadOnlyIntegerProperty focusedIndexProperty
    The index of the current item in the FocusModel which has the focus. It is possible that this will be -1, but only if the control is empty. If the control is not itself focused, this property will still reference the row index that would receive the keyboard focus if the control itself were focused.
    See Also:
      - `getFocusedIndex()`
      - `focusedIndexProperty()`

  - ### focusedItem

    public final ReadOnlyObjectProperty<T> focusedItemProperty
    The current item in the FocusModel which has the focus. It is possible that this will be null, but only if the control is empty. If the control is not itself focused, this property will still reference the item that would receive the keyboard focus if the control itself were focused.
    See Also:
      - `getFocusedItem()`
      - `focusedItemProperty()`

- ## Constructor Details

  - ### FocusModel

    public FocusModel()
    Creates a default FocusModel instance.

- ## Method Details

  - ### focusedIndexProperty

    public final ReadOnlyIntegerProperty focusedIndexProperty()
    The index of the current item in the FocusModel which has the focus. It is possible that this will be -1, but only if the control is empty. If the control is not itself focused, this property will still reference the row index that would receive the keyboard focus if the control itself were focused.
    Returns:
      the `focusedIndex` property
    See Also:
      - `getFocusedIndex()`

  - ### getFocusedIndex

    public final int getFocusedIndex()
    Gets the value of the `focusedIndex` property.
    Property description:
      The index of the current item in the FocusModel which has the focus. It is possible that this will be -1, but only if the control is empty. If the control is not itself focused, this property will still reference the row index that would receive the keyboard focus if the control itself were focused.
    Returns:
      the value of the `focusedIndex` property
    See Also:
      - `focusedIndexProperty()`

  - ### focusedItemProperty

    public final ReadOnlyObjectProperty<T> focusedItemProperty()
    The current item in the FocusModel which has the focus. It is possible that this will be null, but only if the control is empty. If the control is not itself focused, this property will still reference the item that would receive the keyboard focus if the control itself were focused.
    Returns:
      the `focusedItem` property
    See Also:
      - `getFocusedItem()`

  - ### getFocusedItem

    public final T getFocusedItem()
    Gets the value of the `focusedItem` property.
    Property description:
      The current item in the FocusModel which has the focus. It is possible that this will be null, but only if the control is empty. If the control is not itself focused, this property will still reference the item that would receive the keyboard focus if the control itself were focused.
    Returns:
      the value of the `focusedItem` property
    See Also:
      - `focusedItemProperty()`

  - ### getItemCount

    protected abstract int getItemCount()
    Returns the number of items in the data model that underpins the control. An example would be that a ListView focus model would likely return `listView.getItems().size()`. The valid range of focusable indices is between 0 and whatever is returned by this method.
    Returns:
      the number of items in the data model that underpins the control

  - ### getModelItem

    protected abstract T getModelItem(int index)
    Returns the item at the given index. An example using ListView would be `listView.getItems().get(index)`.
    Parameters:
      `index` - The index of the item that is requested from the underlying data model.
    Returns:
      Returns null if the index is out of bounds, or an element of type T that is related to the given index.

  - ### isFocused

    public boolean isFocused(int index)

    Convenience method to inform if the given index is currently focused in this SelectionModel. Is functionally equivalent to calling

        getFocusedIndex() == index

    .
    Parameters:
      `index` - The index to check as to whether it is currently focused or not.
    Returns:
      True if the given index is focused, false otherwise.

  - ### focus

    public void focus(int index)
    Causes the item at the given index to receive the focus. This does not cause the current selection to change. Updates the focusedItem and focusedIndex properties such that `focusedIndex = -1` unless `0 <= index < model size`.
    Parameters:
      `index` - The index of the item to get focus.

  - ### focusPrevious

    public void focusPrevious()
    Attempts to give focus to the row previous to the currently focused row. If the current focus owner is the first row, or is -1 (representing that there is no current focus owner), calling this method will have no result.

  - ### focusNext

    public void focusNext()
    Attempts to give focus to the row after to the currently focused row. If the current focus owner is the last row, calling this method will have no result.