- java.lang.Object
-
- javafx.scene.control.TableColumnBase<S,T>
-
- javafx.scene.control.TableColumn<S,Boolean>
-
- org.controlsfx.control.table.TableRowExpanderColumn<S>
-
- Type Parameters:
S
- The item type of the TableView
- All Implemented Interfaces:
Styleable
,EventTarget
public final class TableRowExpanderColumn<S> extends TableColumn<S,Boolean>
The TableRowExpanderColumn enables a TableView to provide an expandable editor below each table row. The column itself contains a toggle button that on click will show an editor for the current row right below the columns. Example: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 thetoggleExpanded(int)
method to toggle the row expander instead of param.toggleExpanded() like the editor does.
-
-
Property Summary
-
Properties inherited from class javafx.scene.control.TableColumn
cellFactory, cellValueFactory, onEditCancel, onEditCommit, onEditStart, sortType, tableView
-
Properties inherited from 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
Nested Classes Modifier and Type Class 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.-
Nested classes/interfaces inherited from class javafx.scene.control.TableColumn
TableColumn.CellDataFeatures<S extends Object,T extends Object>, TableColumn.CellEditEvent<S extends Object,T extends Object>, TableColumn.SortType
-
-
Field Summary
-
Fields inherited from class javafx.scene.control.TableColumn
DEFAULT_CELL_FACTORY
-
Fields inherited from class javafx.scene.control.TableColumnBase
DEFAULT_COMPARATOR
-
-
Constructor Summary
Constructors Constructor Description TableRowExpanderColumn(Callback<TableRowExpanderColumn.TableRowDataFeatures<S>,Node> expandedNodeCallback)
Create a row expander column that can be added to the TableView list of columns.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Node
getExpandedNode(S item)
Return the expanded node for the given item, if it exists.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.Node
getOrCreateExpandedNode(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.-
Methods inherited from class javafx.scene.control.TableColumn
cellFactoryProperty, cellValueFactoryProperty, editAnyEvent, editCancelEvent, editCommitEvent, editStartEvent, getCellFactory, getCellObservableValue, getCellObservableValue, getCellValueFactory, getClassCssMetaData, getColumns, getCssMetaData, getOnEditCancel, getOnEditCommit, getOnEditStart, getSortType, getStyleableNode, getStyleableParent, getTableView, getTypeSelector, onEditCancelProperty, onEditCommitProperty, onEditStartProperty, setCellFactory, setCellValueFactory, setOnEditCancel, setOnEditCommit, setOnEditStart, setSortType, sortTypeProperty, tableViewProperty
-
Methods inherited from class javafx.scene.control.TableColumnBase
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, 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 inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javafx.event.EventTarget
buildEventDispatchChain
-
-
-
-
Constructor Detail
-
TableRowExpanderColumn
public TableRowExpanderColumn(Callback<TableRowExpanderColumn.TableRowDataFeatures<S>,Node> expandedNodeCallback)
Create a row expander column that can be added to the TableView list of columns. The expandedNodeCallback is expected to return a Node representing the editor that should appear below the table row when the toggle button within the expander column is clicked. Once this column is assigned to a TableView, it will automatically install a custom row factory for the TableView so that it can configure a TableRow with theExpandableTableRowSkin
. It is within the skin that the actual rendering of the expanded node occurs.- Parameters:
expandedNodeCallback
-- See Also:
TableRowExpanderColumn
,TableRowExpanderColumn.TableRowDataFeatures
-
-
Method Detail
-
getExpandedProperty
public 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.- Parameters:
item
- The item corresponding to a table row- Returns:
- The boolean property
-
getOrCreateExpandedNode
public Node getOrCreateExpandedNode(TableRow<S> tableRow)
Get or create and cache the expanded node for a given item.- Parameters:
tableRow
- The table row, used to find the item index- Returns:
- The expanded node for the given item
-
getExpandedNode
public Node getExpandedNode(S item)
Return the expanded node for the given item, if it exists.- Parameters:
item
- The item corresponding to a table row- Returns:
- The expanded node, if it exists.
-
toggleExpanded
public void toggleExpanded(int index)
Toggle the expanded state of the row at the given index.- Parameters:
index
- The index of the row you want to toggle expansion for.
-
-