S - The item type of the TableViewpublic final class TableRowExpanderColumn<S>
extends javafx.scene.control.TableColumn<S,java.lang.Boolean>
TableRowExpanderColumn<Customer> expander = new TableRowExpanderColumn<>(param -> {
HBox editor = new HBox(10);
TextField text = new TextField(param.getValue().getName());
Button save = new Button("Save customer");
save.setOnAction(event -> {
save();
param.toggleExpanded();
});
editor.getChildren().addAll(text, save);
return editor;
});
tableView.getColumns().add(expander);
You can provide a custom cellFactory to customize the toggle button. A typical custom toggle cell implementation
would look like this:
public class MyCustomToggleCell<S> extends TableCell<S, Boolean> {
private Button button = new Button();
public MyCustomToggleCell(TableRowExpanderColumn<S> column) {
button.setOnAction(event -> column.toggleExpanded(getIndex()));
}
protected void updateItem(Boolean expanded, boolean empty) {
super.updateItem(expanded, empty);
if (expanded == null || empty) {
setGraphic(null);
} else {
button.setText(expanded ? "Collapse" : "Expand");
setGraphic(button);
}
}
}
The custom toggle cell utilizes the toggleExpanded(int) method to toggle
the row expander instead of param.toggleExpanded() like the editor does.| Modifier and Type | Class and Description |
|---|---|
static class |
TableRowExpanderColumn.TableRowDataFeatures<S>
This object is passed to the expanded node callback when it is time to create a Node to represent the
expanded editor of a certain row.
|
| Constructor and Description |
|---|
TableRowExpanderColumn(javafx.util.Callback<TableRowExpanderColumn.TableRowDataFeatures<S>,javafx.scene.Node> expandedNodeCallback)
Create a row expander column that can be added to the TableView list of columns.
|
| Modifier and Type | Method and Description |
|---|---|
javafx.scene.Node |
getExpandedNode(S item)
Return the expanded node for the given item, if it exists.
|
javafx.beans.property.BooleanProperty |
getExpandedProperty(S item)
Returns a Boolean property that can be used to manipulate the expanded state for a row
corresponding to the given item value.
|
javafx.scene.Node |
getOrCreateExpandedNode(javafx.scene.control.TableRow<S> tableRow)
Get or create and cache the expanded node for a given item.
|
void |
toggleExpanded(int index)
Toggle the expanded state of the row at the given index.
|
cellFactoryProperty, cellValueFactoryProperty, editAnyEvent, editCancelEvent, editCommitEvent, editStartEvent, getCellFactory, getCellObservableValue, getCellObservableValue, getCellValueFactory, getClassCssMetaData, getColumns, getCssMetaData, getOnEditCancel, getOnEditCommit, getOnEditStart, getSortType, getStyleableParent, getTableView, getTypeSelector, impl_styleableGetNode, onEditCancelProperty, onEditCommitProperty, onEditStartProperty, setCellFactory, setCellValueFactory, setOnEditCancel, setOnEditCommit, setOnEditStart, setSortType, sortTypeProperty, tableViewPropertyaddEventHandler, 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, widthPropertypublic TableRowExpanderColumn(javafx.util.Callback<TableRowExpanderColumn.TableRowDataFeatures<S>,javafx.scene.Node> expandedNodeCallback)
ExpandableTableRowSkin. It is within the skin that the actual
rendering of the expanded node occurs.expandedNodeCallback - TableRowExpanderColumn,
TableRowExpanderColumn.TableRowDataFeaturespublic javafx.beans.property.BooleanProperty getExpandedProperty(S item)
item - The item corresponding to a table rowpublic javafx.scene.Node getOrCreateExpandedNode(javafx.scene.control.TableRow<S> tableRow)
tableRow - The table row, used to find the item indexpublic javafx.scene.Node getExpandedNode(S item)
item - The item corresponding to a table rowpublic void toggleExpanded(int index)
index - The index of the row you want to toggle expansion for.