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.public class TreeTableColumn<S,T> extends TableColumnBase<TreeItem<S>,T>
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:
minWidth
/
prefWidth
/
maxWidth
and width
properties)
visibility
toggled
header text
nested columns
it may contain
context menu
when the user
right-clicks the column header area
comparator
, sortable
and
sortType
)
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: javafx.scene.control.cell.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.TableView
,
TableCell
,
TablePosition
,
javafx.scene.control.cell.TreeItemPropertyValueFactory
Type | Property and Description |
---|---|
<any> |
cellFactory
The cell factory for all cells in this column.
|
<any> |
cellValueFactory
The cell value factory needs to be set to specify how to populate all
cells within a single TreeTableColumn.
|
<any> |
onEditCancel
This event handler will be fired when the user cancels editing a cell.
|
<any> |
onEditCommit
This event handler will be fired when the user successfully commits their
editing.
|
<any> |
onEditStart
This event handler will be fired when the user successfully initiates
editing.
|
<any> |
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. |
<any> |
treeTableView
The TreeTableView that this TreeTableColumn belongs to.
|
comparatorProperty, contextMenuProperty, editableProperty, graphicProperty, idProperty, maxWidthProperty, minWidthProperty, parentColumnProperty, prefWidthProperty, reorderableProperty, resizableProperty, sortableProperty, sortNodeProperty, styleProperty, textProperty, visibleProperty, widthProperty
Modifier and Type | Class and 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.
|
Modifier and Type | Field and Description |
---|---|
private <any> |
cellFactory
The cell factory for all cells in this column.
|
private <any> |
cellValueFactory
The cell value factory needs to be set to specify how to populate all
cells within a single TreeTableColumn.
|
private <any> |
columns
*
Instance Variables *
*
|
private <any> |
columnsListener |
static <any> |
DEFAULT_CELL_FACTORY
If no cellFactory is specified on a TreeTableColumn instance, then this one
will be used by default.
|
private <any> |
DEFAULT_EDIT_COMMIT_HANDLER
*
Listeners *
*
|
private static java.lang.String |
DEFAULT_STYLE_CLASS
*
Stylesheet Handling *
*
|
private static <any> |
EDIT_ANY_EVENT |
private static <any> |
EDIT_CANCEL_EVENT |
private static <any> |
EDIT_COMMIT_EVENT |
private static <any> |
EDIT_START_EVENT |
private <any> |
onEditCancel
This event handler will be fired when the user cancels editing a cell.
|
private <any> |
onEditCommit
This event handler will be fired when the user successfully commits their
editing.
|
private <any> |
onEditStart
This event handler will be fired when the user successfully initiates
editing.
|
private <any> |
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. |
private <any> |
treeTableView
The TreeTableView that this TreeTableColumn belongs to.
|
private <any> |
weakColumnsListener |
DEFAULT_COMPARATOR, DEFAULT_MAX_WIDTH, DEFAULT_MIN_WIDTH, DEFAULT_WIDTH, eventHandlerManager
Constructor and Description |
---|
TreeTableColumn()
Creates a default TreeTableColumn with default cell factory, comparator, and
onEditCommit implementation.
|
TreeTableColumn(java.lang.String text)
Creates a TreeTableColumn with the text set to the provided string, with
default cell factory, comparator, and onEditCommit implementation.
|
Modifier and Type | Method and Description |
---|---|
<any> |
cellFactoryProperty()
The cell factory for all cells in this column.
|
<any> |
cellValueFactoryProperty()
The cell value factory needs to be set to specify how to populate all
cells within a single TreeTableColumn.
|
static <S,T> <any> |
editAnyEvent()
Parent event for any TreeTableColumn edit event.
|
static <S,T> <any> |
editCancelEvent()
Indicates that the editing has been canceled, meaning that no change should
be made to the backing data source.
|
static <S,T> <any> |
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> <any> |
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. |
<any> |
getCellFactory()
Gets the value of the property cellFactory.
|
<any> |
getCellObservableValue(int index)
Attempts to return an ObservableValue<T> for the item in the given
index (which is of type S).
|
<any> |
getCellObservableValue(TreeItem<S> item)
Attempts to return an ObservableValue<T> for the given item (which
is of type S).
|
<any> |
getCellValueFactory()
Gets the value of the property cellValueFactory.
|
static java.util.List<<any>> |
getClassCssMetaData() |
<any> |
getColumns()
This enables support for nested columns, which can be useful to group
together related data.
|
java.util.List<<any>> |
getCssMetaData() |
<any> |
getOnEditCancel()
Gets the value of the property onEditCancel.
|
<any> |
getOnEditCommit()
Gets the value of the property onEditCommit.
|
<any> |
getOnEditStart()
Gets the value of the property onEditStart.
|
TreeTableColumn.SortType |
getSortType()
Gets the value of the property sortType.
|
Node |
getStyleableNode() |
Styleable |
getStyleableParent() |
TreeTableView<S> |
getTreeTableView()
Gets the value of the property treeTableView.
|
java.lang.String |
getTypeSelector() |
<any> |
onEditCancelProperty()
This event handler will be fired when the user cancels editing a cell.
|
<any> |
onEditCommitProperty()
This event handler will be fired when the user successfully commits their
editing.
|
<any> |
onEditStartProperty()
This event handler will be fired when the user successfully initiates
editing.
|
private TableColumnHeader |
scan(TableColumnHeader header) |
void |
setCellFactory(<any> value)
Sets the value of the property cellFactory.
|
void |
setCellValueFactory(<any> value)
Sets the value of the property cellValueFactory.
|
void |
setOnEditCancel(<any> value)
Sets the value of the property onEditCancel.
|
void |
setOnEditCommit(<any> value)
Sets the value of the property onEditCommit.
|
void |
setOnEditStart(<any> value)
Sets the value of the property onEditStart.
|
void |
setSortType(TreeTableColumn.SortType value)
Sets the value of the property sortType.
|
(package private) void |
setTreeTableView(TreeTableView<S> value) |
<any> |
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. |
<any> |
treeTableViewProperty()
The TreeTableView that this TreeTableColumn belongs to.
|
addEventHandler, buildEventDispatchChain, comparatorProperty, contextMenuProperty, doSetWidth, editableProperty, getCellData, getCellData, getComparator, getContextMenu, getGraphic, getId, getMaxWidth, getMinWidth, getParentColumn, getPrefWidth, getProperties, getPseudoClassStates, getSortNode, getStyle, 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, setParentColumn, setPrefWidth, setReorderable, setResizable, setSortable, setSortNode, setStyle, setText, setUserData, setVisible, setWidth, sortableProperty, sortNodeProperty, styleProperty, textProperty, updateColumnWidths, visibleProperty, widthProperty
public final <any> treeTableViewProperty
getTreeTableView()
public final <any> 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 javafx.scene.control.cell.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"));
getCellValueFactory()
,
#setCellValueFactory()
public final <any> 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.
getCellFactory()
,
#setCellFactory()
public final <any> 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.getSortType()
,
setSortType(SortType)
public final <any> onEditStartProperty
getOnEditStart()
,
#setOnEditStart()
public final <any> onEditCommitProperty
getOnEditCommit()
,
#setOnEditCommit()
public final <any> onEditCancelProperty
getOnEditCancel()
,
#setOnEditCancel()
private static final <any> EDIT_ANY_EVENT
private static final <any> EDIT_START_EVENT
private static final <any> EDIT_CANCEL_EVENT
private static final <any> EDIT_COMMIT_EVENT
public static final <any> 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.private <any> DEFAULT_EDIT_COMMIT_HANDLER
private <any> columnsListener
private <any> weakColumnsListener
private final <any> columns
private <any> treeTableView
private <any> cellValueFactory
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 javafx.scene.control.cell.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"));
javafx.scene.control.cell.TreeItemPropertyValueFactory
private final <any> cellFactory
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.
private <any> sortType
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.private <any> onEditStart
private <any> onEditCommit
private <any> onEditCancel
private static final java.lang.String DEFAULT_STYLE_CLASS
public TreeTableColumn()
public TreeTableColumn(java.lang.String text)
text
- The string to show when the TreeTableColumn is placed within
the TreeTableView.public static <S,T> <any> editAnyEvent()
S
- the type of the TreeTableView generic typeT
- the type of the content in all cells in this TreeTableColumnpublic static <S,T> <any> editStartEvent()
TreeTableView.edit(int, javafx.scene.control.TreeTableColumn)
method has been called.S
- the type of the TreeTableView generic typeT
- the type of the content in all cells in this TreeTableColumnpublic static <S,T> <any> editCancelEvent()
S
- the type of the TreeTableView generic typeT
- the type of the content in all cells in this TreeTableColumnpublic static <S,T> <any> editCommitEvent()
S
- the type of the TreeTableView generic typeT
- the type of the content in all cells in this TreeTableColumnpublic final <any> treeTableViewProperty()
getTreeTableView()
final void setTreeTableView(TreeTableView<S> value)
public final TreeTableView<S> getTreeTableView()
public final void setCellValueFactory(<any> value)
public final <any> getCellValueFactory()
public final <any> 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 javafx.scene.control.cell.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"));
getCellValueFactory()
,
#setCellValueFactory()
public final void setCellFactory(<any> value)
public final <any> getCellFactory()
public final <any> 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.
getCellFactory()
,
#setCellFactory()
public final <any> 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.getSortType()
,
setSortType(SortType)
public final void setSortType(TreeTableColumn.SortType value)
public final TreeTableColumn.SortType getSortType()
public final void setOnEditStart(<any> value)
public final <any> getOnEditStart()
public final <any> onEditStartProperty()
getOnEditStart()
,
#setOnEditStart()
public final void setOnEditCommit(<any> value)
public final <any> getOnEditCommit()
public final <any> onEditCommitProperty()
getOnEditCommit()
,
#setOnEditCommit()
public final void setOnEditCancel(<any> value)
public final <any> getOnEditCancel()
public final <any> onEditCancelProperty()
getOnEditCancel()
,
#setOnEditCancel()
public final <any> getColumns()
This has no impact on the table as such - all column indices point to the leaf columns only, and it isn't possible to sort using the parent column, just the leaf columns. In other words, this is purely a visual feature.
getColumns
in class TableColumnBase<TreeItem<S>,T>
public final <any> getCellObservableValue(int index)
This is achieved by calling the cell value factory
, and
returning whatever it returns when passed a CellDataFeatures
(see,
for example, the CellDataFeatures classes belonging to
TableColumn
and
TreeTableColumn
for more
information).
getCellObservableValue
in class TableColumnBase<TreeItem<S>,T>
index
- The index of the item (of type S) for which an
ObservableValue<T> is sought.public final <any> getCellObservableValue(TreeItem<S> item)
This is achieved by calling the cell value factory
, and
returning whatever it returns when passed a CellDataFeatures
(see,
for example, the CellDataFeatures classes belonging to
TableColumn
and
TreeTableColumn
for more
information).
getCellObservableValue
in class TableColumnBase<TreeItem<S>,T>
item
- The item (of type S) for which an ObservableValue<T> is
sought.public java.lang.String getTypeSelector()
public Styleable getStyleableParent()
getTreeTableView()
public java.util.List<<any>> getCssMetaData()
public static java.util.List<<any>> getClassCssMetaData()
public Node getStyleableNode()
private TableColumnHeader scan(TableColumnHeader header)