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

public Class ComboBoxTableCell<S, T>

extends TableCell<S, T>
Class Inheritance
Type Parameters
<S>
The type of the TableView generic type
<T>
The type of the elements contained within the TableColumn.
Static Imports
javafx.scene.control.cell.CellUtils.createComboBox

A class containing a TableCell implementation that draws a ComboBox node inside the cell.

By default, the ComboBoxTableCell is rendered as a Label when not being edited, and as a ComboBox when in editing mode. The ComboBox will, by default, stretch to fill the entire table cell.

To create a ComboBoxTableCell, it is necessary to provide zero or more items that will be shown to the user when the ComboBox menu is showing. These items must be of the same type as the TableColumn.

Since
JavaFX 2.2

Field Summary

Modifier and TypeField and Description
private ComboBox<T>
private BooleanProperty
private ObjectProperty<StringConverter<T>>
private final ObservableList<T>

Constructor Summary

AccessConstructor and Description
public
ComboBoxTableCell()

Creates a default ComboBoxTableCell with an empty items list.

public
ComboBoxTableCell(T...
The items to show in the ComboBox popup menu when selected by the user.
items
)

Creates a default ComboBoxTableCell instance with the given items being used to populate the ComboBox when it is shown.

public
ComboBoxTableCell(StringConverter<T>
A StringConverter that can convert an item of type T into a user-readable string so that it may then be shown in the ComboBox popup menu.
converter
,
T...
The items to show in the ComboBox popup menu when selected by the user.
items
)

Creates a ComboBoxTableCell instance with the given items being used to populate the ComboBox when it is shown, and the StringConverter being used to convert the item in to a user-readable form.

public
ComboBoxTableCell(ObservableList<T>
The items to show in the ComboBox popup menu when selected by the user.
items
)

Creates a default ComboBoxTableCell instance with the given items being used to populate the ComboBox when it is shown.

public
ComboBoxTableCell(StringConverter<T>
A StringConverter that can convert an item of type T into a user-readable string so that it may then be shown in the ComboBox popup menu.
converter
,
ObservableList<T>
The items to show in the ComboBox popup menu when selected by the user.
items
)

Creates a ComboBoxTableCell instance with the given items being used to populate the ComboBox when it is shown, and the StringConverter being used to convert the item in to a user-readable form.

Method Summary

Modifier and TypeMethod and Description
public void
cancelEdit()

Overrides javafx.scene.control.TableCell.cancelEdit.

Cancels an edit to the value of the cell.

public final BooleanProperty

Returns:

the property representing whether the ComboBox, when shown to the user, is editable or not
comboBoxEditableProperty
()

A property representing whether the ComboBox, when shown to the user, is editable or not.

public final ObjectProperty<StringConverter<T>>

Returns:

the StringConverter property
converterProperty
()

The StringConverter property.

public static <
The type of the TableView generic type
S
,
The type of the elements contained within the TableColumn.
T
>
Callback<TableColumn<S, T>, TableCell<S, T>>

Returns:

A Callback that will return a TableCell that is able to work on the type of element contained within the TableColumn.
forTableColumn
(final T...
Zero or more items that will be shown to the user when the ComboBox menu is showing. These items must be of the same type as the TableColumn. Note that it is up to the developer to set event handlers to listen to edit events in the TableColumn, and react accordingly. Methods of interest include setOnEditStart, setOnEditCommit, and setOnEditCancel.
items
)

Creates a ComboBox cell factory for use in TableColumn controls.

public static <
The type of the TableView generic type
S
,
The type of the elements contained within the TableColumn.
T
>
Callback<TableColumn<S, T>, TableCell<S, T>>

Returns:

A Callback that will return a TableCell that is able to work on the type of element contained within the TableColumn.
forTableColumn
(final StringConverter<T>
A StringConverter to convert the given item (of type T) to a String for displaying to the user.
converter
,
final T...
Zero or more items that will be shown to the user when the ComboBox menu is showing. These items must be of the same type as the TableColumn. Note that it is up to the developer to set event handlers to listen to edit events in the TableColumn, and react accordingly. Methods of interest include setOnEditStart, setOnEditCommit, and setOnEditCancel.
items
)

Creates a ComboBox cell factory for use in TableColumn controls.

public static <
The type of the TableView generic type
S
,
The type of the elements contained within the TableColumn.
T
>
Callback<TableColumn<S, T>, TableCell<S, T>>

Returns:

A Callback that will return a TableCell that is able to work on the type of element contained within the TableColumn.
forTableColumn
(final ObservableList<T>
Zero or more items that will be shown to the user when the ComboBox menu is showing. These items must be of the same type as the TableColumn. Note that it is up to the developer to set event handlers to listen to edit events in the TableColumn, and react accordingly. Methods of interest include setOnEditStart, setOnEditCommit, and setOnEditCancel.
items
)

Creates a ComboBox cell factory for use in TableColumn controls.

public static <
The type of the TableView generic type
S
,
The type of the elements contained within the TableColumn.
T
>
Callback<TableColumn<S, T>, TableCell<S, T>>

Returns:

A Callback that will return a TableCell that is able to work on the type of element contained within the TableColumn.
forTableColumn
(final StringConverter<T>
A StringConverter to convert the given item (of type T) to a String for displaying to the user.
converter
,
final ObservableList<T>
Zero or more items that will be shown to the user when the ComboBox menu is showing. These items must be of the same type as the TableColumn. Note that it is up to the developer to set event handlers to listen to edit events in the TableColumn, and react accordingly. Methods of interest include setOnEditStart, setOnEditCommit, and setOnEditCancel.
items
)

Creates a ComboBox cell factory for use in TableColumn controls.

public final StringConverter<T>

Returns:

the StringConverter used in this cell
getConverter
()

Returns the StringConverter used in this cell.

public ObservableList<T>

Returns:

the items to be displayed in this ComboBox when it is showing
getItems
()

Returns the items to be displayed in the ComboBox when it is showing.

public final boolean

Returns:

true if the ComboBox is editable
isComboBoxEditable
()

Returns true if the ComboBox is editable.

public final void
setComboBoxEditable(boolean
the editable value to be set for this ComboBox
value
)

Configures the ComboBox to be editable (to allow user input outside of the options provide in the dropdown list).

public final void
setConverter(StringConverter<T>
the StringConverter to be used in this cell
value
)

Sets the StringConverter to be used in this cell.

public void
startEdit()

Overrides javafx.scene.control.TableCell.startEdit.

Starts an edit to the value of the cell.

public void
updateItem(T item, boolean empty)

Overrides javafx.scene.control.Cell.updateItem.

The updateItem method should not be called by developers, but it is the best method for developers to override to allow for them to customise the visuals of the cell.

Inherited from javafx.scene.control.TableCell:
commitEditcreateDefaultSkinexecuteAccessibleActiongetTableColumngetTableRowgetTableViewlayoutChildrenqueryAccessibleAttributetableColumnPropertytableRowPropertytableViewPropertyupdateSelectedupdateTableColumnupdateTableRowupdateTableView

Field Detail

comboBoxback to summary
private ComboBox<T> comboBox
comboBoxEditableback to summary
private BooleanProperty comboBoxEditable
converterback to summary
private ObjectProperty<StringConverter<T>> converter
itemsback to summary
private final ObservableList<T> items

Constructor Detail

ComboBoxTableCellback to summary
public ComboBoxTableCell()

Creates a default ComboBoxTableCell with an empty items list.

ComboBoxTableCellback to summary
public ComboBoxTableCell(T... items)

Creates a default ComboBoxTableCell instance with the given items being used to populate the ComboBox when it is shown.

Parameters
items:T[]

The items to show in the ComboBox popup menu when selected by the user.

Annotations
@SafeVarargs
ComboBoxTableCellback to summary
public ComboBoxTableCell(StringConverter<T> converter, T... items)

Creates a ComboBoxTableCell instance with the given items being used to populate the ComboBox when it is shown, and the StringConverter being used to convert the item in to a user-readable form.

Parameters
converter:StringConverter<T>

A StringConverter that can convert an item of type T into a user-readable string so that it may then be shown in the ComboBox popup menu.

items:T[]

The items to show in the ComboBox popup menu when selected by the user.

Annotations
@SafeVarargs
ComboBoxTableCellback to summary
public ComboBoxTableCell(ObservableList<T> items)

Creates a default ComboBoxTableCell instance with the given items being used to populate the ComboBox when it is shown.

Parameters
items:ObservableList<T>

The items to show in the ComboBox popup menu when selected by the user.

ComboBoxTableCellback to summary
public ComboBoxTableCell(StringConverter<T> converter, ObservableList<T> items)

Creates a ComboBoxTableCell instance with the given items being used to populate the ComboBox when it is shown, and the StringConverter being used to convert the item in to a user-readable form.

Parameters
converter:StringConverter<T>

A StringConverter that can convert an item of type T into a user-readable string so that it may then be shown in the ComboBox popup menu.

items:ObservableList<T>

The items to show in the ComboBox popup menu when selected by the user.

Method Detail

cancelEditback to summary
public void cancelEdit()

Overrides javafx.scene.control.TableCell.cancelEdit.

Doc from javafx.scene.control.TableCell.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
comboBoxEditablePropertyback to summary
public final BooleanProperty comboBoxEditableProperty()

A property representing whether the ComboBox, when shown to the user, is editable or not.

Returns:BooleanProperty

the property representing whether the ComboBox, when shown to the user, is editable or not

converterPropertyback to summary
public final ObjectProperty<StringConverter<T>> converterProperty()

The StringConverter property.

Returns:ObjectProperty<StringConverter<T>>

the StringConverter property

forTableColumnback to summary
public static <S, T> Callback<TableColumn<S, T>, TableCell<S, T>> forTableColumn(final T... items)

Creates a ComboBox cell factory for use in TableColumn controls. By default, the ComboBoxCell is rendered as a Label when not being edited, and as a ComboBox when in editing mode. The ComboBox will, by default, stretch to fill the entire list cell.

Parameters
<S>
The type of the TableView generic type
<T>
The type of the elements contained within the TableColumn.
items:T[]

Zero or more items that will be shown to the user when the ComboBox menu is showing. These items must be of the same type as the TableColumn. Note that it is up to the developer to set event handlers to listen to edit events in the TableColumn, and react accordingly. Methods of interest include setOnEditStart, setOnEditCommit, and setOnEditCancel.

Returns:Callback<TableColumn<S, T>, TableCell<S, T>>

A Callback that will return a TableCell that is able to work on the type of element contained within the TableColumn.

Annotations
@SafeVarargs
forTableColumnback to summary
public static <S, T> Callback<TableColumn<S, T>, TableCell<S, T>> forTableColumn(final StringConverter<T> converter, final T... items)

Creates a ComboBox cell factory for use in TableColumn controls. By default, the ComboBoxCell is rendered as a Label when not being edited, and as a ComboBox when in editing mode. The ComboBox will, by default, stretch to fill the entire list cell.

Parameters
<S>
The type of the TableView generic type
<T>
The type of the elements contained within the TableColumn.
converter:StringConverter<T>

A StringConverter to convert the given item (of type T) to a String for displaying to the user.

items:T[]

Zero or more items that will be shown to the user when the ComboBox menu is showing. These items must be of the same type as the TableColumn. Note that it is up to the developer to set event handlers to listen to edit events in the TableColumn, and react accordingly. Methods of interest include setOnEditStart, setOnEditCommit, and setOnEditCancel.

Returns:Callback<TableColumn<S, T>, TableCell<S, T>>

A Callback that will return a TableCell that is able to work on the type of element contained within the TableColumn.

Annotations
@SafeVarargs
forTableColumnback to summary
public static <S, T> Callback<TableColumn<S, T>, TableCell<S, T>> forTableColumn(final ObservableList<T> items)

Creates a ComboBox cell factory for use in TableColumn controls. By default, the ComboBoxCell is rendered as a Label when not being edited, and as a ComboBox when in editing mode. The ComboBox will, by default, stretch to fill the entire list cell.

Parameters
<S>
The type of the TableView generic type
<T>
The type of the elements contained within the TableColumn.
items:ObservableList<T>

Zero or more items that will be shown to the user when the ComboBox menu is showing. These items must be of the same type as the TableColumn. Note that it is up to the developer to set event handlers to listen to edit events in the TableColumn, and react accordingly. Methods of interest include setOnEditStart, setOnEditCommit, and setOnEditCancel.

Returns:Callback<TableColumn<S, T>, TableCell<S, T>>

A Callback that will return a TableCell that is able to work on the type of element contained within the TableColumn.

forTableColumnback to summary
public static <S, T> Callback<TableColumn<S, T>, TableCell<S, T>> forTableColumn(final StringConverter<T> converter, final ObservableList<T> items)

Creates a ComboBox cell factory for use in TableColumn controls. By default, the ComboBoxCell is rendered as a Label when not being edited, and as a ComboBox when in editing mode. The ComboBox will, by default, stretch to fill the entire list cell.

Parameters
<S>
The type of the TableView generic type
<T>
The type of the elements contained within the TableColumn.
converter:StringConverter<T>

A StringConverter to convert the given item (of type T) to a String for displaying to the user.

items:ObservableList<T>

Zero or more items that will be shown to the user when the ComboBox menu is showing. These items must be of the same type as the TableColumn. Note that it is up to the developer to set event handlers to listen to edit events in the TableColumn, and react accordingly. Methods of interest include setOnEditStart, setOnEditCommit, and setOnEditCancel.

Returns:Callback<TableColumn<S, T>, TableCell<S, T>>

A Callback that will return a TableCell that is able to work on the type of element contained within the TableColumn.

getConverterback to summary
public final StringConverter<T> getConverter()

Returns the StringConverter used in this cell.

Returns:StringConverter<T>

the StringConverter used in this cell

getItemsback to summary
public ObservableList<T> getItems()

Returns the items to be displayed in the ComboBox when it is showing.

Returns:ObservableList<T>

the items to be displayed in this ComboBox when it is showing

isComboBoxEditableback to summary
public final boolean isComboBoxEditable()

Returns true if the ComboBox is editable.

Returns:boolean

true if the ComboBox is editable

setComboBoxEditableback to summary
public final void setComboBoxEditable(boolean value)

Configures the ComboBox to be editable (to allow user input outside of the options provide in the dropdown list).

Parameters
value:boolean

the editable value to be set for this ComboBox

setConverterback to summary
public final void setConverter(StringConverter<T> value)

Sets the StringConverter to be used in this cell.

Parameters
value:StringConverter<T>

the StringConverter to be used in this cell

startEditback to summary
public void startEdit()

Overrides javafx.scene.control.TableCell.startEdit.

Doc from javafx.scene.control.TableCell.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
updateItemback to summary
public void updateItem(T item, boolean empty)

Overrides javafx.scene.control.Cell.updateItem.

Doc from javafx.scene.control.Cell.updateItem.

The updateItem method should not be called by developers, but it is the best method for developers to override to allow for them to customise the visuals of the cell. To clarify, developers should never call this method in their code (they should leave it up to the UI control, such as the javafx.scene.control.ListView control) to call this method. However, the purpose of having the updateItem method is so that developers, when specifying custom cell factories (again, like the ListView cell factory), the updateItem method can be overridden to allow for complete customisation of the cell.

It is very important that subclasses of Cell override the updateItem method properly, as failure to do so will lead to issues such as blank cells or cells with unexpected content appearing within them. Here is an example of how to properly override the updateItem method:

protected void updateItem(T item, boolean empty) {
    super.updateItem(item, empty);

    if (empty || item == null) {
        setText(null);
        setGraphic(null);
    } else {
        setText(item.toString());
    }
}

Note in this code sample two important points:

  1. We call the super.updateItem(T, boolean) method. If this is not done, the item and empty properties are not correctly set, and you are likely to end up with graphical issues.
  2. We test for the empty condition, and if true, we set the text and graphic properties to null. If we do not do this, it is almost guaranteed that end users will see graphical artifacts in cells unexpectedly.
Annotations
@Override