Class TreeTableColumn<S,T>
- Type Parameters:
-
S- The type of the TableView generic type (i.e. S == TableView<S>) -
T- The type of the content in all cells in this TableColumn.
- All Implemented Interfaces:
-
Styleable,EventTarget
public class TreeTableColumn<S,T>
extends TableColumnBase<TreeItem<S>,T>
implements EventTarget TreeTableView is made up of a number of TreeTableColumn instances. Each TreeTableColumn in a TreeTableView is responsible for displaying (and editing) the contents of that column. As well as being responsible for displaying and editing data for a single column, a TreeTableColumn also contains the necessary properties to: - Be resized (using
minWidth/prefWidth/maxWidthandwidthproperties) - Have its
visibilitytoggled - Display
header text - Display any
nested columnsit may contain - Have a
context menuwhen the user right-clicks the column header area - Have the contents of the table be sorted (using
comparator,sortableandsortType)
text (what to show in the column header area), and the column cell value factory (which is used to populate individual cells in the column). This can be achieved using some variation on the following code:
firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<Person, String> p) {
// p.getValue() returns the TreeItem<Person> instance for a particular TreeTableView row,
// p.getValue().getValue() returns the Person instance inside the TreeItem<Person>
return p.getValue().getValue().firstNameProperty();
}
});
} This approach assumes that the object returned from p.getValue().getValue() has a JavaFX ObservableValue that can simply be returned. The benefit of this is that the TableView will internally create bindings to ensure that, should the returned ObservableValue change, the cell contents will be automatically refreshed. In situations where a TableColumn must interact with classes created before JavaFX, or that generally do not wish to use JavaFX APIs for properties, it is possible to wrap the returned value in a ReadOnlyObjectWrapper instance. For example:
firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<Person, String> p) {
// p.getValue() returns the TreeItem<Person> instance for a particular TreeTableView row,
// p.getValue().getValue() returns the Person instance inside the TreeItem<Person>
return new ReadOnlyObjectWrapper(p.getValue().getValue().getFirstName());
}
});
} It is hoped that over time there will be convenience cell value factories developed and made available to developers. As of the JavaFX 2.0 release, there is one such convenience class: TreeItemPropertyValueFactory. This class removes the need to write the code above, instead relying on reflection to look up a given property from a String. Refer to the TreeItemPropertyValueFactory class documentation for more information on how to use this with a TableColumn. Finally, for more detail on how to use TableColumn, there is further documentation in the TableView class documentation.- Since:
- JavaFX 8.0
- See Also:
-
TableView,TableCell,TablePosition,TreeItemPropertyValueFactory
Property Summary
| Type | Property | Description |
|---|---|---|
ObjectProperty<Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>>> | cellFactory | The cell factory for all cells in this column. |
ObjectProperty<Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>>> | cellValueFactory | The cell value factory needs to be set to specify how to populate all cells within a single TreeTableColumn. |
ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> | onEditCancel | This event handler will be fired when the user cancels editing a cell. |
ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> | onEditCommit | This event handler will be fired when the user successfully commits their editing. |
ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> | onEditStart | This event handler will be fired when the user successfully initiates editing. |
ObjectProperty<TreeTableColumn.SortType> | sortType | Used to state whether this column, if it is part of a sort order (see TreeTableView.getSortOrder() for more details), should be sorted in ascending or descending order. |
ReadOnlyObjectProperty<TreeTableView<S>> | treeTableView | The TreeTableView that this TreeTableColumn belongs to. |
Properties declared in class javafx.scene.control.TableColumnBase
comparator, contextMenu, editable, graphic, id, maxWidth, minWidth, parentColumn, prefWidth, reorderable, resizable, sortable, sortNode, style, text, visible, width
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
static class | TreeTableColumn.CellDataFeatures<S,T> | A support class used in TreeTableColumn as a wrapper class to provide all necessary information for a particular Cell. |
static class | TreeTableColumn.CellEditEvent<S,T> | An event that is fired when a user performs an edit on a table cell. |
static class | TreeTableColumn.SortType | Enumeration that specifies the type of sorting being applied to a specific column. |
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
static Callback<TreeTableColumn<?,?>,TreeTableCell<?,?>> | DEFAULT_CELL_FACTORY | If no cellFactory is specified on a TreeTableColumn instance, then this one will be used by default. |
Fields declared in class javafx.scene.control.TableColumnBase
DEFAULT_COMPARATOR
Constructor Summary
| Constructor | Description |
|---|---|
TreeTableColumn() | Creates a default TreeTableColumn with default cell factory, comparator, and onEditCommit implementation. |
TreeTableColumn(String text) | Creates a TreeTableColumn with the text set to the provided string, with default cell factory, comparator, and onEditCommit implementation. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
ObjectProperty<Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>>> | cellFactoryProperty() | The cell factory for all cells in this column. |
ObjectProperty<Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>>> | cellValueFactoryProperty() | The cell value factory needs to be set to specify how to populate all cells within a single TreeTableColumn. |
static <S,
T> EventType<TreeTableColumn.CellEditEvent<S,T>> | editAnyEvent() | Parent event for any TreeTableColumn edit event. |
static <S,
T> EventType<TreeTableColumn.CellEditEvent<S,T>> | editCancelEvent() | Indicates that the editing has been canceled, meaning that no change should be made to the backing data source. |
static <S,
T> EventType<TreeTableColumn.CellEditEvent<S,T>> | editCommitEvent() | Indicates that the editing has been committed by the user, meaning that a change should be made to the backing data source to reflect the new data. |
static <S,
T> EventType<TreeTableColumn.CellEditEvent<S,T>> | editStartEvent() | Indicates that the user has performed some interaction to start an edit event, or alternatively the TreeTableView.edit(int, javafx.scene.control.TreeTableColumn) method has been called. |
Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>> | getCellFactory() | Gets the value of the property cellFactory. |
Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>> | getCellValueFactory() | Gets the value of the property cellValueFactory. |
static List<CssMetaData<? extends Styleable,?>> | getClassCssMetaData() | |
EventHandler<TreeTableColumn.CellEditEvent<S,T>> | getOnEditCancel() | Gets the value of the property onEditCancel. |
EventHandler<TreeTableColumn.CellEditEvent<S,T>> | getOnEditCommit() | Gets the value of the property onEditCommit. |
EventHandler<TreeTableColumn.CellEditEvent<S,T>> | getOnEditStart() | Gets the value of the property onEditStart. |
TreeTableColumn.SortType | getSortType() | Gets the value of the property sortType. |
Styleable | getStyleableParent() | Return the parent of this Styleable, or null if there is no parent. |
TreeTableView<S> | getTreeTableView() | Gets the value of the property treeTableView. |
String | getTypeSelector() | The type of this Styleable that is to be used in selector matching. |
ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> | onEditCancelProperty() | This event handler will be fired when the user cancels editing a cell. |
ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> | onEditCommitProperty() | This event handler will be fired when the user successfully commits their editing. |
ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> | onEditStartProperty() | This event handler will be fired when the user successfully initiates editing. |
void | setCellFactory(Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>> value) | Sets the value of the property cellFactory. |
void | setCellValueFactory(Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>> value) | Sets the value of the property cellValueFactory. |
void | setOnEditCancel(EventHandler<TreeTableColumn.CellEditEvent<S,T>> value) | Sets the value of the property onEditCancel. |
void | setOnEditCommit(EventHandler<TreeTableColumn.CellEditEvent<S,T>> value) | Sets the value of the property onEditCommit. |
void | setOnEditStart(EventHandler<TreeTableColumn.CellEditEvent<S,T>> value) | Sets the value of the property onEditStart. |
void | setSortType(TreeTableColumn.SortType value) | Sets the value of the property sortType. |
ObjectProperty<TreeTableColumn.SortType> | sortTypeProperty() | Used to state whether this column, if it is part of a sort order (see TreeTableView.getSortOrder() for more details), should be sorted in ascending or descending order. |
ReadOnlyObjectProperty<TreeTableView<S>> | treeTableViewProperty() | The TreeTableView that this TreeTableColumn belongs to. |
Methods declared in class javafx.scene.control.TableColumnBase
addEventHandler, comparatorProperty, contextMenuProperty, editableProperty, getCellData, getCellData, getCellObservableValue, getCellObservableValue, getColumns, getComparator, getContextMenu, getGraphic, getMaxWidth, getMinWidth, getParentColumn, getPrefWidth, getProperties, getSortNode, getStyleClass, getText, getUserData, getWidth, graphicProperty, hasProperties, idProperty, isEditable, isReorderable, isResizable, isSortable, isVisible, maxWidthProperty, minWidthProperty, parentColumnProperty, prefWidthProperty, removeEventHandler, reorderableProperty, resizableProperty, setComparator, setContextMenu, setEditable, setGraphic, setId, setMaxWidth, setMinWidth, setPrefWidth, setReorderable, setResizable, setSortable, setSortNode, setStyle, setText, setUserData, setVisible, sortableProperty, sortNodeProperty, styleProperty, textProperty, visibleProperty, widthProperty
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface javafx.event.EventTarget
buildEventDispatchChain
Methods declared in interface javafx.css.Styleable
getCssMetaData, getId, getPseudoClassStates, getStyle, getStyleableNode
Property Details
treeTableView
public final ReadOnlyObjectProperty<TreeTableView<S>> treeTableViewProperty
- See Also:
getTreeTableView()
cellValueFactory
public final ObjectProperty<Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>>> cellValueFactoryProperty
Callback that provides a TreeTableColumn.CellDataFeatures instance, and expects an ObservableValue to be returned. The returned ObservableValue instance will be observed internally to allow for updates to the value to be immediately reflected on screen. An example of how to set a cell value factory is:
firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<Person, String> p) {
// p.getValue() returns the TreeItem<Person> instance for a particular TreeTableView row,
// p.getValue().getValue() returns the Person instance inside the TreeItem<Person>
return p.getValue().getValue().firstNameProperty();
}
});
} A common approach is to want to populate cells in a TreeTableColumn using a single value from a Java bean. To support this common scenario, there is the TreeItemPropertyValueFactory class. Refer to this class for more information on how to use it, but briefly here is how the above use case could be simplified using the TreeItemPropertyValueFactory class:
firstNameCol.setCellValueFactory(new TreeItemPropertyValueFactory<Person,String>("firstName"));
- See Also:
-
getCellValueFactory(),setCellValueFactory(Callback)
cellFactory
public final ObjectProperty<Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>>> cellFactoryProperty
By default TreeTableColumn uses a default cell
factory, but this can be replaced with a custom implementation, for example to show data in a different way or to support editing. There is a lot of documentation on creating custom cell factories elsewhere (see Cell and TreeTableView for example).
Finally, there are a number of pre-built cell factories available in the javafx.scene.control.cell package.
- See Also:
-
getCellFactory(),setCellFactory(Callback)
sortType
public final ObjectProperty<TreeTableColumn.SortType> sortTypeProperty
TreeTableView.getSortOrder() for more details), should be sorted in ascending or descending order. Simply toggling this property will result in the sort order changing in the TreeTableView, assuming of course that this column is in the sortOrder ObservableList to begin with.- See Also:
-
getSortType(),setSortType(TreeTableColumn.SortType)
onEditStart
public final ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> onEditStartProperty
- See Also:
-
getOnEditStart(),setOnEditStart(EventHandler)
onEditCommit
public final ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> onEditCommitProperty
- See Also:
-
getOnEditCommit(),setOnEditCommit(EventHandler)
onEditCancel
public final ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> onEditCancelProperty
- See Also:
-
getOnEditCancel(),setOnEditCancel(EventHandler)
Field Details
DEFAULT_CELL_FACTORY
public static final Callback<TreeTableColumn<?,?>,TreeTableCell<?,?>> DEFAULT_CELL_FACTORY
graphic property if the item is a Node, or it simply calls toString() if it is not null, setting the resulting string inside the text property.Constructor Details
TreeTableColumn
public TreeTableColumn()
TreeTableColumn
public TreeTableColumn(String text)
- Parameters:
-
text- The string to show when the TreeTableColumn is placed within the TreeTableView.
Method Details
editAnyEvent
public static <S, T> EventType<TreeTableColumn.CellEditEvent<S,T>> editAnyEvent()
- Type Parameters:
-
S- the type of the TreeTableView generic type -
T- the type of the content in all cells in this TreeTableColumn - Returns:
- the edit event
editStartEvent
public static <S, T> EventType<TreeTableColumn.CellEditEvent<S,T>> editStartEvent()
TreeTableView.edit(int, javafx.scene.control.TreeTableColumn) method has been called.- Type Parameters:
-
S- the type of the TreeTableView generic type -
T- the type of the content in all cells in this TreeTableColumn - Returns:
- the edit start event
editCancelEvent
public static <S, T> EventType<TreeTableColumn.CellEditEvent<S,T>> editCancelEvent()
- Type Parameters:
-
S- the type of the TreeTableView generic type -
T- the type of the content in all cells in this TreeTableColumn - Returns:
- the edit cancel event
editCommitEvent
public static <S, T> EventType<TreeTableColumn.CellEditEvent<S,T>> editCommitEvent()
- Type Parameters:
-
S- the type of the TreeTableView generic type -
T- the type of the content in all cells in this TreeTableColumn - Returns:
- the edit commit event
treeTableViewProperty
public final ReadOnlyObjectProperty<TreeTableView<S>> treeTableViewProperty()
- See Also:
getTreeTableView()
getTreeTableView
public final TreeTableView<S> getTreeTableView()
- Property description:
- The TreeTableView that this TreeTableColumn belongs to.
setCellValueFactory
public final void setCellValueFactory(Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>> value)
- Property description:
- The cell value factory needs to be set to specify how to populate all cells within a single TreeTableColumn. A cell value factory is a
Callbackthat provides aTreeTableColumn.CellDataFeaturesinstance, and expects anObservableValueto be returned. The returned ObservableValue instance will be observed internally to allow for updates to the value to be immediately reflected on screen.An example of how to set a cell value factory is:
A common approach is to want to populate cells in a TreeTableColumn using a single value from a Java bean. To support this common scenario, there is thefirstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() { public ObservableValue<String> call(CellDataFeatures<Person, String> p) { // p.getValue() returns the TreeItem<Person> instance for a particular TreeTableView row, // p.getValue().getValue() returns the Person instance inside the TreeItem<Person> return p.getValue().getValue().firstNameProperty(); } });}TreeItemPropertyValueFactoryclass. Refer to this class for more information on how to use it, but briefly here is how the above use case could be simplified using the TreeItemPropertyValueFactory class:firstNameCol.setCellValueFactory(new TreeItemPropertyValueFactory<Person,String>("firstName"));
getCellValueFactory
public final Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>> getCellValueFactory()
- Property description:
- The cell value factory needs to be set to specify how to populate all cells within a single TreeTableColumn. A cell value factory is a
Callbackthat provides aTreeTableColumn.CellDataFeaturesinstance, and expects anObservableValueto be returned. The returned ObservableValue instance will be observed internally to allow for updates to the value to be immediately reflected on screen.An example of how to set a cell value factory is:
A common approach is to want to populate cells in a TreeTableColumn using a single value from a Java bean. To support this common scenario, there is thefirstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() { public ObservableValue<String> call(CellDataFeatures<Person, String> p) { // p.getValue() returns the TreeItem<Person> instance for a particular TreeTableView row, // p.getValue().getValue() returns the Person instance inside the TreeItem<Person> return p.getValue().getValue().firstNameProperty(); } });}TreeItemPropertyValueFactoryclass. Refer to this class for more information on how to use it, but briefly here is how the above use case could be simplified using the TreeItemPropertyValueFactory class:firstNameCol.setCellValueFactory(new TreeItemPropertyValueFactory<Person,String>("firstName"));
cellValueFactoryProperty
public final ObjectProperty<Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>>> cellValueFactoryProperty()
Callback that provides a TreeTableColumn.CellDataFeatures instance, and expects an ObservableValue to be returned. The returned ObservableValue instance will be observed internally to allow for updates to the value to be immediately reflected on screen. An example of how to set a cell value factory is:
firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<Person, String> p) {
// p.getValue() returns the TreeItem<Person> instance for a particular TreeTableView row,
// p.getValue().getValue() returns the Person instance inside the TreeItem<Person>
return p.getValue().getValue().firstNameProperty();
}
});
} A common approach is to want to populate cells in a TreeTableColumn using a single value from a Java bean. To support this common scenario, there is the TreeItemPropertyValueFactory class. Refer to this class for more information on how to use it, but briefly here is how the above use case could be simplified using the TreeItemPropertyValueFactory class:
firstNameCol.setCellValueFactory(new TreeItemPropertyValueFactory<Person,String>("firstName"));
- See Also:
-
getCellValueFactory(),setCellValueFactory(Callback)
setCellFactory
public final void setCellFactory(Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>> value)
- Property description:
- The cell factory for all cells in this column. The cell factory is responsible for rendering the data contained within each TreeTableCell for a single TreeTableColumn.
By default TreeTableColumn uses a
default cell factory, but this can be replaced with a custom implementation, for example to show data in a different way or to support editing. There is a lot of documentation on creating custom cell factories elsewhere (seeCellandTreeTableViewfor example).Finally, there are a number of pre-built cell factories available in the
javafx.scene.control.cellpackage.
getCellFactory
public final Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>> getCellFactory()
- Property description:
- The cell factory for all cells in this column. The cell factory is responsible for rendering the data contained within each TreeTableCell for a single TreeTableColumn.
By default TreeTableColumn uses a
default cell factory, but this can be replaced with a custom implementation, for example to show data in a different way or to support editing. There is a lot of documentation on creating custom cell factories elsewhere (seeCellandTreeTableViewfor example).Finally, there are a number of pre-built cell factories available in the
javafx.scene.control.cellpackage.
cellFactoryProperty
public final ObjectProperty<Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>>> cellFactoryProperty()
By default TreeTableColumn uses a default cell
factory, but this can be replaced with a custom implementation, for example to show data in a different way or to support editing. There is a lot of documentation on creating custom cell factories elsewhere (see Cell and TreeTableView for example).
Finally, there are a number of pre-built cell factories available in the javafx.scene.control.cell package.
- See Also:
-
getCellFactory(),setCellFactory(Callback)
sortTypeProperty
public final ObjectProperty<TreeTableColumn.SortType> sortTypeProperty()
TreeTableView.getSortOrder() for more details), should be sorted in ascending or descending order. Simply toggling this property will result in the sort order changing in the TreeTableView, assuming of course that this column is in the sortOrder ObservableList to begin with.- See Also:
-
getSortType(),setSortType(TreeTableColumn.SortType)
setSortType
public final void setSortType(TreeTableColumn.SortType value)
- Property description:
- Used to state whether this column, if it is part of a sort order (see
TreeTableView.getSortOrder()for more details), should be sorted in ascending or descending order. Simply toggling this property will result in the sort order changing in the TreeTableView, assuming of course that this column is in the sortOrder ObservableList to begin with.
getSortType
public final TreeTableColumn.SortType getSortType()
- Property description:
- Used to state whether this column, if it is part of a sort order (see
TreeTableView.getSortOrder()for more details), should be sorted in ascending or descending order. Simply toggling this property will result in the sort order changing in the TreeTableView, assuming of course that this column is in the sortOrder ObservableList to begin with.
setOnEditStart
public final void setOnEditStart(EventHandler<TreeTableColumn.CellEditEvent<S,T>> value)
- Property description:
- This event handler will be fired when the user successfully initiates editing.
getOnEditStart
public final EventHandler<TreeTableColumn.CellEditEvent<S,T>> getOnEditStart()
- Property description:
- This event handler will be fired when the user successfully initiates editing.
onEditStartProperty
public final ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> onEditStartProperty()
- See Also:
-
getOnEditStart(),setOnEditStart(EventHandler)
setOnEditCommit
public final void setOnEditCommit(EventHandler<TreeTableColumn.CellEditEvent<S,T>> value)
- Property description:
- This event handler will be fired when the user successfully commits their editing.
getOnEditCommit
public final EventHandler<TreeTableColumn.CellEditEvent<S,T>> getOnEditCommit()
- Property description:
- This event handler will be fired when the user successfully commits their editing.
onEditCommitProperty
public final ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> onEditCommitProperty()
- See Also:
-
getOnEditCommit(),setOnEditCommit(EventHandler)
setOnEditCancel
public final void setOnEditCancel(EventHandler<TreeTableColumn.CellEditEvent<S,T>> value)
- Property description:
- This event handler will be fired when the user cancels editing a cell.
getOnEditCancel
public final EventHandler<TreeTableColumn.CellEditEvent<S,T>> getOnEditCancel()
- Property description:
- This event handler will be fired when the user cancels editing a cell.
onEditCancelProperty
public final ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> onEditCancelProperty()
- See Also:
-
getOnEditCancel(),setOnEditCancel(EventHandler)
getTypeSelector
public String getTypeSelector()
Styleable that is to be used in selector matching. This is analogous to an "element" in HTML. (CSS Type Selector).- Specified by:
-
getTypeSelectorin interfaceStyleable - Returns:
- "TreeTableColumn"
getStyleableParent
public Styleable getStyleableParent()
- Specified by:
-
getStyleableParentin interfaceStyleable - Returns:
getTreeTableView()
getClassCssMetaData
public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.