Top Description Inners Fields Constructors Methods
org.controlsfx.control.table

public final Class TableRowExpanderColumn<S>

extends TableColumn<S, Boolean>
Class Inheritance
Type Parameters
<S>
The item type of the TableView
Imports
impl.org.controlsfx.skin.ExpandableTableRowSkin, javafx.beans.property.BooleanProperty, .SimpleBooleanProperty, javafx.geometry.Insets, javafx.scene.Node, javafx.scene.control.*, javafx.util.Callback, java.util.HashMap, .Map

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 TableRowExpanderColumn#toggleExpanded(int) method to toggle the row expander instead of param.toggleExpanded() like the editor does.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
TableRowExpanderColumn.TableRowDataFeatures<
The type of items in the TableView
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.

private class
TableRowExpanderColumn.ToggleCell

The default toggle cell creates a button with a + or - sign as the text, depending on the expanded state of the row it represents.

Field Summary

Modifier and TypeField and Description
private final Map<S, Node>
private Callback<TableRowExpanderColumn.TableRowDataFeatures<S>, Node>
private static final String
private final Map<S, BooleanProperty>
private static final String
Inherited from javafx.scene.control.TableColumn:
DEFAULT_CELL_FACTORY

Constructor Summary

AccessConstructor and Description
public
TableRowExpanderColumn(Callback<TableRowExpanderColumn.TableRowDataFeatures<S>, Node> expandedNodeCallback)

Create a row expander column that can be added to the TableView list of columns.

Method Summary

Modifier and TypeMethod and Description
public Node

Returns:

The expanded node, if it exists.
getExpandedNode
(S
The item corresponding to a table row
item
)

Return the expanded node for the given item, if it exists.

public BooleanProperty

Returns:

The boolean property
getExpandedProperty
(S
The item corresponding to a table row
item
)

Returns a Boolean property that can be used to manipulate the expanded state for a row corresponding to the given item value.

public Node

Returns:

The expanded node for the given item
getOrCreateExpandedNode
(TableRow<S>
The table row, used to find the item index
tableRow
)

Get or create and cache the expanded node for a given item.

private void
installRowFactoryOnTableViewAssignment()

Install the row factory on the TableView when this column is assigned to a TableView.

public void
toggleExpanded(int
The index of the row you want to toggle expansion for.
index
)

Toggle the expanded state of the row at the given index.

Inherited from javafx.scene.control.TableColumn:
cellFactoryPropertycellValueFactoryPropertyeditAnyEventeditCancelEventeditCommitEventeditStartEventgetCellFactorygetCellObservableValuegetCellObservableValuegetCellValueFactorygetClassCssMetaDatagetColumnsgetCssMetaDatagetOnEditCancelgetOnEditCommitgetOnEditStartgetSortTypegetStyleableNodegetStyleableParentgetTableViewgetTypeSelectoronEditCancelPropertyonEditCommitPropertyonEditStartPropertysetCellFactorysetCellValueFactorysetOnEditCancelsetOnEditCommitsetOnEditStartsetSortTypesortTypePropertytableViewProperty

Field Detail

expandedNodeCacheback to summary
private final Map<S, Node> expandedNodeCache
expandedNodeCallbackback to summary
private Callback<TableRowExpanderColumn.TableRowDataFeatures<S>, Node> expandedNodeCallback
EXPANDER_BUTTON_STYLE_CLASSback to summary
private static final String EXPANDER_BUTTON_STYLE_CLASS
expansionStateback to summary
private final Map<S, BooleanProperty> expansionState
STYLE_CLASSback to summary
private static final String STYLE_CLASS

Constructor Detail

TableRowExpanderColumnback to summary
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 the impl.org.controlsfx.skin.ExpandableTableRowSkin. It is within the skin that the actual rendering of the expanded node occurs.

See Also
TableRowExpanderColumn, TableRowDataFeatures

Method Detail

getExpandedNodeback to summary
public Node getExpandedNode(S item)

Return the expanded node for the given item, if it exists.

Parameters
item:S

The item corresponding to a table row

Returns:Node

The expanded node, if it exists.

getExpandedPropertyback to summary
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:S

The item corresponding to a table row

Returns:BooleanProperty

The boolean property

getOrCreateExpandedNodeback to summary
public Node getOrCreateExpandedNode(TableRow<S> tableRow)

Get or create and cache the expanded node for a given item.

Parameters
tableRow:TableRow<S>

The table row, used to find the item index

Returns:Node

The expanded node for the given item

installRowFactoryOnTableViewAssignmentback to summary
private void installRowFactoryOnTableViewAssignment()

Install the row factory on the TableView when this column is assigned to a TableView.

toggleExpandedback to summary
public void toggleExpanded(int index)

Toggle the expanded state of the row at the given index.

Parameters
index:int

The index of the row you want to toggle expansion for.

org.controlsfx.control.table back to summary

public final Class TableRowExpanderColumn.TableRowDataFeatures<S>

extends Object
Class Inheritance
  • java.lang.Object
  • org.controlsfx.control.table.TableRowExpanderColumn.TableRowDataFeatures
Type Parameters
<S>
The type of items in the TableView

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. The most important method is getValue()} which returns the object represented by the current row. Further more, the expandedProperty() returns a boolean property indicating the current expansion state of the current row. You can use this, or the toggleExpanded() method to toggle and inspect the expanded state of the row, for example if you want an action inside the row editor to contract the editor.

Field Summary

Modifier and TypeField and Description
private BooleanProperty
private TableRowExpanderColumn<S>
private TableRow<S>
private S

Constructor Summary

AccessConstructor and Description
public
TableRowDataFeatures(TableRow<S> tableRow, TableRowExpanderColumn<S> tableColumn, S value)

Method Summary

Modifier and TypeMethod and Description
public BooleanProperty

Returns:

The expanded property
expandedProperty
()

The expanded property can be used to inspect or mutate the toggled state of this row editor.

public TableRowExpanderColumn<S>

Returns:

The TableColumn which contains the toggle button
getTableColumn
()

Return the TableColumn which contains the toggle button.

public TableRow<S>

Returns:

The current TableRow
getTableRow
()

Return the current TableRow.

public S

Returns:

The value represented by the current table row
getValue
()

The value represented by the current table row.

public Boolean

Returns:

A boolean indicating the expanded state of the current editor
isExpanded
()

Returns a boolean indicating if the current row is expanded or not

public void
setExpanded(Boolean
Wheter the row editor should be expanded or not
expanded
)

Set the expanded state.

public void
toggleExpanded()

Toggle the expanded state of this row editor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

expandedPropertyback to summary
private BooleanProperty expandedProperty
tableColumnback to summary
private TableRowExpanderColumn<S> tableColumn
tableRowback to summary
private TableRow<S> tableRow
valueback to summary
private S value

Constructor Detail

TableRowDataFeaturesback to summary
public TableRowDataFeatures(TableRow<S> tableRow, TableRowExpanderColumn<S> tableColumn, S value)

Method Detail

expandedPropertyback to summary
public BooleanProperty expandedProperty()

The expanded property can be used to inspect or mutate the toggled state of this row editor. You can also listen for changes to it's state if needed.

Returns:BooleanProperty

The expanded property

getTableColumnback to summary
public TableRowExpanderColumn<S> getTableColumn()

Return the TableColumn which contains the toggle button. Normally you would not need to use this directly, but rather consult the expandedProperty() for inspection and mutation of the toggled state of this row.

Returns:TableRowExpanderColumn<S>

The TableColumn which contains the toggle button

getTableRowback to summary
public TableRow<S> getTableRow()

Return the current TableRow. It is safe to assume that the index returned by TableRow#getIndex() is correct as long as you use it for the initial node creation. It is not safe to trust the result of this call at any later time, for example in a button action within the row editor.

Returns:TableRow<S>

The current TableRow

getValueback to summary
public S getValue()

The value represented by the current table row. It is important that the value has valid equals/hashCode methods, as the row value is used to keep track of the node editor for each row.

Returns:S

The value represented by the current table row

isExpandedback to summary
public Boolean isExpanded()

Returns a boolean indicating if the current row is expanded or not

Returns:Boolean

A boolean indicating the expanded state of the current editor

setExpandedback to summary
public void setExpanded(Boolean expanded)

Set the expanded state. This will update the expandedProperty() accordingly.

Parameters
expanded:Boolean

Wheter the row editor should be expanded or not

toggleExpandedback to summary
public void toggleExpanded()

Toggle the expanded state of this row editor.

org.controlsfx.control.table back to summary

private final Class TableRowExpanderColumn.ToggleCell

extends TableCell<S, Boolean>
Class Inheritance

The default toggle cell creates a button with a + or - sign as the text, depending on the expanded state of the row it represents. You can use this as a starting point to implement a custom toggle cell.

Field Summary

Modifier and TypeField and Description
private Button

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
updateItem(Boolean expanded, boolean empty)

Overrides javafx.scene.control.Cell.updateItem.

The updateItem method should not be called by developers, but it is the best method for developers to override to allow for them to customise the visuals of the cell.

Inherited from javafx.scene.control.TableCell:
cancelEditcommitEditcreateDefaultSkinexecuteAccessibleActiongetTableColumngetTableRowgetTableViewlayoutChildrenqueryAccessibleAttributestartEdittableColumnPropertytableRowPropertytableViewPropertyupdateSelectedupdateTableColumnupdateTableRowupdateTableView

Field Detail

buttonback to summary
private Button button

Constructor Detail

ToggleCellback to summary
public ToggleCell()

Method Detail

updateItemback to summary
protected void updateItem(Boolean expanded, boolean empty)

Overrides javafx.scene.control.Cell.updateItem.

Doc from javafx.scene.control.Cell.updateItem.

The updateItem method should not be called by developers, but it is the best method for developers to override to allow for them to customise the visuals of the cell. To clarify, developers should never call this method in their code (they should leave it up to the UI control, such as the javafx.scene.control.ListView control) to call this method. However, the purpose of having the updateItem method is so that developers, when specifying custom cell factories (again, like the ListView cell factory), the updateItem method can be overridden to allow for complete customisation of the cell.

It is very important that subclasses of Cell override the updateItem method properly, as failure to do so will lead to issues such as blank cells or cells with unexpected content appearing within them. Here is an example of how to properly override the updateItem method:

protected void updateItem(T item, boolean empty) {
    super.updateItem(item, empty);

    if (empty || item == null) {
        setText(null);
        setGraphic(null);
    } else {
        setText(item.toString());
    }
}

Note in this code sample two important points:

  1. We call the super.updateItem(T, boolean) method. If this is not done, the item and empty properties are not correctly set, and you are likely to end up with graphical issues.
  2. We test for the empty condition, and if true, we set the text and graphic properties to null. If we do not do this, it is almost guaranteed that end users will see graphical artifacts in cells unexpectedly.
Annotations
@Override