Class TableRowExpanderColumn<S>

  • Type Parameters:
    S - The item type of the TableView
    All Implemented Interfaces:
    javafx.css.Styleable, javafx.event.EventTarget

    public final class TableRowExpanderColumn<S>
    extends javafx.scene.control.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 the toggleExpanded(int) method to toggle the row expander instead of param.toggleExpanded() like the editor does.
    • 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

        javafx.scene.control.TableColumn.CellDataFeatures<S extends Object,​T extends Object>, javafx.scene.control.TableColumn.CellEditEvent<S extends Object,​T extends Object>, javafx.scene.control.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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      • 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 interface javafx.event.EventTarget

        buildEventDispatchChain
    • Constructor Detail

      • TableRowExpanderColumn

        public 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. 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 the ExpandableTableRowSkin. 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 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.
        Parameters:
        item - The item corresponding to a table row
        Returns:
        The boolean property
      • getOrCreateExpandedNode

        public javafx.scene.Node getOrCreateExpandedNode​(javafx.scene.control.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 javafx.scene.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.