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> 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:
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: 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
,
TreeItemPropertyValueFactory
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 |
---|---|
static Callback<TreeTableColumn<?,?>,TreeTableCell<?,?>> |
DEFAULT_CELL_FACTORY
If no cellFactory is specified on a TreeTableColumn instance, then this one
will be used by default.
|
DEFAULT_COMPARATOR
Constructor and 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.
|
addEventHandler, buildEventDispatchChain, comparatorProperty, contextMenuProperty, editableProperty, getCellData, getCellData, getComparator, getContextMenu, getGraphic, getId, getMaxWidth, getMinWidth, getParentColumn, getPrefWidth, getProperties, getPseudoClassStates, getSortNode, getStyle, getStyleClass, getText, getUserData, getWidth, graphicProperty, hasProperties, idProperty, impl_fixedProperty, impl_isFixed, impl_isReorderable, impl_reorderableProperty, impl_setFixed, impl_setReorderable, impl_setWidth, isEditable, isResizable, isSortable, isVisible, maxWidthProperty, minWidthProperty, parentColumnProperty, prefWidthProperty, removeEventHandler, resizableProperty, setComparator, setContextMenu, setEditable, setGraphic, setId, setMaxWidth, setMinWidth, setPrefWidth, setResizable, setSortable, setSortNode, setStyle, setText, setUserData, setVisible, sortableProperty, sortNodeProperty, styleProperty, textProperty, visibleProperty, widthProperty
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
buildEventDispatchChain
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.public TreeTableColumn()
public TreeTableColumn(String text)
text
- The string to show when the TreeTableColumn is placed within
the TreeTableView.public static <S,T> EventType<TreeTableColumn.CellEditEvent<S,T>> editAnyEvent()
public static <S,T> EventType<TreeTableColumn.CellEditEvent<S,T>> editStartEvent()
TreeTableView.edit(int, javafx.scene.control.TreeTableColumn)
method has been called.public static <S,T> EventType<TreeTableColumn.CellEditEvent<S,T>> editCancelEvent()
public static <S,T> EventType<TreeTableColumn.CellEditEvent<S,T>> editCommitEvent()
public final ReadOnlyObjectProperty<TreeTableView<S>> treeTableViewProperty()
public final TreeTableView<S> getTreeTableView()
public final void setCellValueFactory(Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>> value)
public final Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>> getCellValueFactory()
public final ObjectProperty<Callback<TreeTableColumn.CellDataFeatures<S,T>,ObservableValue<T>>> cellValueFactoryProperty()
public final void setCellFactory(Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>> value)
public final Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>> getCellFactory()
public final ObjectProperty<Callback<TreeTableColumn<S,T>,TreeTableCell<S,T>>> cellFactoryProperty()
public final ObjectProperty<TreeTableColumn.SortType> sortTypeProperty()
public final void setSortType(TreeTableColumn.SortType value)
public final TreeTableColumn.SortType getSortType()
public final void setOnEditStart(EventHandler<TreeTableColumn.CellEditEvent<S,T>> value)
public final EventHandler<TreeTableColumn.CellEditEvent<S,T>> getOnEditStart()
public final ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> onEditStartProperty()
public final void setOnEditCommit(EventHandler<TreeTableColumn.CellEditEvent<S,T>> value)
public final EventHandler<TreeTableColumn.CellEditEvent<S,T>> getOnEditCommit()
public final ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> onEditCommitProperty()
public final void setOnEditCancel(EventHandler<TreeTableColumn.CellEditEvent<S,T>> value)
public final EventHandler<TreeTableColumn.CellEditEvent<S,T>> getOnEditCancel()
public final ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<S,T>>> onEditCancelProperty()
public final ObservableList<TreeTableColumn<S,?>> 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 ObservableValue<T> 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 ObservableValue<T> 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 String getTypeSelector()
Styleable
that is to be used in selector matching.
This is analogous to an "element" in HTML.
(CSS Type Selector).getTypeSelector
in interface Styleable
public Styleable getStyleableParent()
getStyleableParent
in interface Styleable
getTreeTableView()
public List<CssMetaData<? extends Styleable,?>> getCssMetaData()
getCssMetaData
in interface Styleable
public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
@Deprecated public Node impl_styleableGetNode()
Copyright © 2020. All rights reserved.