APIdia Launch Partner
Top Description Fields Constructors Methods
javafx.scene.control

public Class ListCell<T>

extends IndexedCell<T>
Class Inheritance
Known Direct Subclasses
javafx.scene.control.cell.CheckBoxListCell, javafx.scene.control.cell.ChoiceBoxListCell, javafx.scene.control.cell.ComboBoxListCell, javafx.scene.control.cell.TextFieldListCell
Type Parameters
<T>
The type of the item contained within the ListCell.
Imports
java.lang.ref.WeakReference, java.util.List, javafx.application.Platform, javafx.beans.InvalidationListener, .Observable, .WeakInvalidationListener, javafx.beans.property.ReadOnlyObjectProperty, .ReadOnlyObjectWrapper, javafx.beans.value.ChangeListener, .ObservableValue, .WeakChangeListener, javafx.collections.ListChangeListener, .ObservableList, .WeakListChangeListener, javafx.scene.AccessibleAction, .AccessibleAttribute, .AccessibleRole, javafx.scene.control.skin.ListCellSkin

The Cell type used within ListView instances. In addition to the API defined on Cell and IndexedCell, the ListCell is more tightly bound to a ListView, allowing for better support of editing events, etc.

A ListView maintains selection, indicating which cell(s) have been selected, and focus, indicating the current focus owner for any given ListView. For each property, each ListCell has a boolean reflecting whether this specific cell is selected or focused. To achieve this, each ListCell has a reference back to the ListView that it is being used within. Each ListCell belongs to one and only one ListView.

Note that in the case of virtualized controls like ListView, when a cell has focus this is not in the same sense as application focus. When a ListCell has focus it simply represents the fact that the cell will receive keyboard events in the situation that the owning ListView actually contains focus. Of course, in the case where a cell has a Node set in the graphic property, it is completely legal for this Node to request, and acquire focus as would normally be expected.

Since
JavaFX 2.0

Field Summary

Modifier and TypeField and Description
private static final String
private final InvalidationListener
editingListener

Listens to the editing index on the ListView.

private boolean
private final InvalidationListener
focusedListener

Listens to the focus model on the ListView.

private final ChangeListener<FocusModel<T>>
focusModelPropertyListener

Listens to the focusModel property on the ListView.

private int
private final ListChangeListener<T>
itemsListener

Listens to the items on the ListView.

private final InvalidationListener
itemsPropertyListener

Listens to the items property on the ListView.

private ReadOnlyObjectWrapper<ListView<T>>
listView

The ListView associated with this Cell.

private final ListChangeListener<Integer>
selectedListener

Listens to the selection model on the ListView.

private final ChangeListener<MultipleSelectionModel<T>>
selectionModelPropertyListener

Listens to the selectionModel property on the ListView.

private boolean
private final WeakInvalidationListener
private final WeakInvalidationListener
private final WeakChangeListener<FocusModel<T>>
private final WeakListChangeListener<T>
private final WeakInvalidationListener
private final WeakListChangeListener<Integer>
private final WeakChangeListener<MultipleSelectionModel<T>>

Constructor Summary

AccessConstructor and Description
public
ListCell()

Creates a default ListCell with the default style class of 'list-cell'.

Method Summary

Modifier and TypeMethod and Description
public void
cancelEdit()

Overrides javafx.scene.control.Cell.cancelEdit.

Cancels an edit to the value of the cell.

public void
commitEdit(T newValue)

Overrides javafx.scene.control.Cell.commitEdit.

Commits an edit to the value of the cell.

protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control.

public void
executeAccessibleAction(AccessibleAction action, Object... parameters)

Overrides javafx.scene.control.Control.executeAccessibleAction.

This method is called by the assistive technology to request the action indicated by the argument should be executed.

public final ListView<T>
pack-priv void
indexChanged(int oldIndex, int newIndex)

Overrides javafx.scene.control.IndexedCell.indexChanged.

This method is called whenever the index is changed, regardless of whether the new index is the same as the old index.

protected void
layoutChildren()

Overrides javafx.scene.control.Cell.layoutChildren.

Invoked during the layout pass to layout the children in this Parent.

public final ReadOnlyObjectProperty<ListView<T>>
public Object
queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides javafx.scene.control.Control.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

private void
public void
startEdit()

Overrides javafx.scene.control.Cell.startEdit.

Starts an edit to the value of the cell.

private void
private void
private void
updateItem(int oldIndex)

public final void
updateListView(ListView<T>
the ListView associated with this cell
listView
)

Updates the ListView associated with this Cell.

private void
Inherited from javafx.scene.control.IndexedCell:
getIndexindexPropertyupdateIndex

Field Detail

DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS

Hides javafx.scene.control.IndexedCell.DEFAULT_STYLE_CLASS.

editingListenerback to summary
private final InvalidationListener editingListener

Listens to the editing index on the ListView. It is possible for the developer to call the ListView#edit(int) method and cause a specific cell to start editing. In such a case, we need to be notified so we can call startEdit on our side.

firstRunback to summary
private boolean firstRun
focusedListenerback to summary
private final InvalidationListener focusedListener

Listens to the focus model on the ListView. Whenever the focus model changes, the focused property on the ListCell is updated

focusModelPropertyListenerback to summary
private final ChangeListener<FocusModel<T>> focusModelPropertyListener

Listens to the focusModel property on the ListView. Whenever the entire model is changed, we have to unhook the weakFocusedListener and update the focus.

indexAtStartEditback to summary
private int indexAtStartEdit
itemsListenerback to summary
private final ListChangeListener<T> itemsListener

Listens to the items on the ListView. Whenever the items are changed in such a way that it impacts the index of this ListCell, then we must update the item.

itemsPropertyListenerback to summary
private final InvalidationListener itemsPropertyListener

Listens to the items property on the ListView. Whenever the entire list is changed, we have to unhook the weakItemsListener and update the item.

listViewback to summary
private ReadOnlyObjectWrapper<ListView<T>> listView

The ListView associated with this Cell.

selectedListenerback to summary
private final ListChangeListener<Integer> selectedListener

Listens to the selection model on the ListView. Whenever the selection model is changed (updated), the selected property on the ListCell is updated accordingly.

selectionModelPropertyListenerback to summary
private final ChangeListener<MultipleSelectionModel<T>> selectionModelPropertyListener

Listens to the selectionModel property on the ListView. Whenever the entire model is changed, we have to unhook the weakSelectedListener and update the selection.

updateEditingIndexback to summary
private boolean updateEditingIndex
weakEditingListenerback to summary
private final WeakInvalidationListener weakEditingListener
weakFocusedListenerback to summary
private final WeakInvalidationListener weakFocusedListener
weakFocusModelPropertyListenerback to summary
private final WeakChangeListener<FocusModel<T>> weakFocusModelPropertyListener
weakItemsListenerback to summary
private final WeakListChangeListener<T> weakItemsListener
weakItemsPropertyListenerback to summary
private final WeakInvalidationListener weakItemsPropertyListener
weakSelectedListenerback to summary
private final WeakListChangeListener<Integer> weakSelectedListener
weakSelectionModelPropertyListenerback to summary
private final WeakChangeListener<MultipleSelectionModel<T>> weakSelectionModelPropertyListener

Constructor Detail

ListCellback to summary
public ListCell()

Creates a default ListCell with the default style class of 'list-cell'.

Method Detail

cancelEditback to summary
public void cancelEdit()

Overrides javafx.scene.control.Cell.cancelEdit.

Doc from javafx.scene.control.Cell.cancelEdit.

Cancels an edit to the value of the cell. Call this function to transition from an editing state into a non-editing state, without saving any user input.

Annotations
@Override
commitEditback to summary
public void commitEdit(T newValue)

Overrides javafx.scene.control.Cell.commitEdit.

Doc from javafx.scene.control.Cell.commitEdit.

Commits an edit to the value of the cell. Call this function when appropriate (based on the user interaction requirements of your cell editing user interface) to do two things:

  1. Fire the appropriate events back to the backing UI control (e.g., ListView). This will begin the process of pushing this edit back to the relevant data source / property (although it does not guarantee that this will be successful - that is dependent upon the specific edit commit handler being used). Refer to the UI control class javadoc for more detail.
  2. Begin the transition from an editing state into a non-editing state.

In general there is no need to override this method in custom cell implementations - it should be sufficient to simply call this method when appropriate (e.g., when the user pressed the Enter key, you may do something like cell.commitEdit(converter.fromString(textField.getText()));

Annotations
@Override
createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Doc from javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
executeAccessibleActionback to summary
public void executeAccessibleAction(AccessibleAction action, Object... parameters)

Overrides javafx.scene.control.Control.executeAccessibleAction.

Doc from javafx.scene.control.Control.executeAccessibleAction.

This method is called by the assistive technology to request the action indicated by the argument should be executed.

This method is commonly overridden by subclasses to implement action that are required for a specific role.
If a particular action is not handled, the superclass implementation must be called.

Annotations
@Override
getListViewback to summary
public final ListView<T> getListView()
indexChangedback to summary
pack-priv void indexChanged(int oldIndex, int newIndex)

Overrides javafx.scene.control.IndexedCell.indexChanged.

Doc from javafx.scene.control.IndexedCell.indexChanged.

This method is called whenever the index is changed, regardless of whether the new index is the same as the old index.

Annotations
@Override
layoutChildrenback to summary
protected void layoutChildren()

Overrides javafx.scene.control.Cell.layoutChildren.

Doc from javafx.scene.control.Cell.layoutChildren.

Invoked during the layout pass to layout the children in this Parent. By default it will only set the size of managed, resizable content to their preferred sizes and does not do any node positioning.

Subclasses should override this function to layout content as needed.

Annotations
@Override
listViewPropertyback to summary
public final ReadOnlyObjectProperty<ListView<T>> listViewProperty()
queryAccessibleAttributeback to summary
public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides javafx.scene.control.Control.queryAccessibleAttribute.

Doc from javafx.scene.control.Control.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

This method is commonly overridden by subclasses to implement attributes that are required for a specific role.
If a particular attribute is not handled, the superclass implementation must be called.

Annotations
@Override
setListViewback to summary
private void setListView(ListView<T> value)
startEditback to summary
public void startEdit()

Overrides javafx.scene.control.Cell.startEdit.

Doc from javafx.scene.control.Cell.startEdit.

Starts an edit to the value of the cell. Call this function to transition from a non-editing state into an editing state, if the cell is editable. If this cell is already in an editing state, it will stay in it.

Annotations
@Override
updateEditingback to summary
private void updateEditing()
updateFocusback to summary
private void updateFocus()
updateItemback to summary
private void updateItem(int oldIndex)
updateListViewback to summary
public final void updateListView(ListView<T> listView)

Updates the ListView associated with this Cell.

Note

This function is intended to be used by experts, primarily by those implementing new Skins. It is not common for developers or designers to access this function directly.

Parameters
listView:ListView<T>

the ListView associated with this cell

updateSelectionback to summary
private void updateSelection()