Class TableView2<S>

Type Parameters:
S - The type of the objects contained within the TableView2 items list.
All Implemented Interfaces:
Styleable, EventTarget, Skinnable
Direct Known Subclasses:
FilteredTableView

public class TableView2<S> extends TableView<S>
The TableView2 is an advanced JavaFX TableView control, that can be used as drop-in replacement control for the existing TableView, and provides different functionalities and use cases.

Features

  • Rows can be fixed to the top of the TableView2 so that they are always visible on screen.
  • Columns can be fixed to the left of the TableView2 so that they are always visible on screen.
  • A row header can be switched on in order to display any custom content.
  • The column header can be extended to provide custom content.
  • FilteredTableView is a subclass of TableView2 with extended filtering options

Fixing Rows and Columns


Rows and columns can be fixed using dedicated actions like ColumnFixAction and RowFixAction. When fixed, the header's background will show a darker color. For instance, these actions can be attached to a ContextMenu that can be installed to the row header cells with rowHeaderContextMenuFactory.
You have also the possibility to fix them manually by adding and removing items from getFixedRows() and getFixedColumns(). But you are strongly advised to check if it's possible to do so with isColumnFixable(int) for the fixed columns and with isRowFixable(int) for the fixed rows.

If you want to fix several rows or columns together, you can call areRowsFixable(List) or areTableViewColumnsFixable(List) to verify if you can fix them. Calling those methods prior every move will ensure that no exception will be thrown.
You have also the possibility to deactivate these features.

Row Headers


You can also access and toggle row header's visibility by using the method provided setRowHeaderVisible(boolean). By default the row header will show the row index, but you can set the content with setRowHeader(TableColumn).

Cell editing


Two specialized cell factories are available TextField2TableCell and ComboBox2TableCell, providing support for commit on focus lost.

Filtering options


While filtering can be implemented as in a regular JavaFX TableView control, see FilteredTableView for extended filtering options.

Features not supported


Cell spanning is not supported yet.

Sample

Let's provide the underlying data model, based on a Person class.

 
 public class Person {
     private StringProperty firstName;
     public void setFirstName(String value) { firstNameProperty().set(value); }
     public String getFirstName() { return firstNameProperty().get(); }
     public StringProperty firstNameProperty() {
         if (firstName == null) firstName = new SimpleStringProperty(this, "firstName");
         return firstName;
     }

     private StringProperty lastName;
     public void setLastName(String value) { lastNameProperty().set(value); }
     public String getLastName() { return lastNameProperty().get(); }
     public StringProperty lastNameProperty() {
         if (lastName == null) lastName = new SimpleStringProperty(this, "lastName");
         return lastName;
     }
 }

A TableView2 can be created, and filled with an observable list of people:

 
 TableView2<Person> table = new TableView2<Person>();
 ObservableList<Person> people = getPeople();
 table.setItems(people);
 

Now we add two columns to the table:

 
 TableColumn2<Person,String> firstNameCol = new TableColumn2<>("First Name");
 firstNameCol.setCellValueFactory(p -> p.getValue().firstNameProperty());
 TableColumn2<Person,String> lastNameCol = new TableColumn2<>("Last Name");
 lastNameCol.setCellValueFactory(p -> p.getValue().lastNameProperty());

 table.getColumns().setAll(firstNameCol, lastNameCol);

A cell factory that allows commit on focus lost can be set:

 
 firstName.setCellFactory(TextField2TableCell.forTableColumn());

We can fix some row and columns, and also show the row header:

 
 table.getFixedColumns().setAll(firstNameColumn);
 table.getFixedRows().setAll(0, 1, 2);

 table.setRowHeaderVisible(true);
  • Property Details

  • Constructor Details

    • TableView2

      public TableView2()
      Creates a TableView2 control with no content.
    • TableView2

      public TableView2(ObservableList<S> items)
      Creates a TableView2 with the content provided in the items ObservableList.
      Parameters:
      items - The items to insert into the TableView2, and the list to watch for changes (to automatically show in the TableView2).
  • Method Details

    • getRowSpan

      public int getRowSpan(TablePosition<?,?> pos, int index)
      Return the current row span at the given position in the Table. If a sort is applied to the TableView2, some spanned cells may be splitted.
      Parameters:
      pos - the TablePosition
      index - the index
      Returns:
      the current row span for the given cell.
    • getColumnSpan

      public int getColumnSpan(TablePosition<?,?> pos)
      Return the current column span.
      Parameters:
      pos - The TablePosition
      Returns:
      the current column span of a Cell.
    • getFixedRows

      public final ObservableList<Integer> getFixedRows()
      You can fix or unfix a row by modifying this list. Call isRowFixable(int) before trying to fix a row. See TableView2 description for information.
      Returns:
      an ObservableList of integer representing the fixedRows.
    • isRowFixable

      public final boolean isRowFixable(int row)
      Indicate whether a row can be fixed or not. Call that method before adding an item with getFixedRows() . A row cannot be fixed alone if any cell inside the row has a row span superior to one.
      Parameters:
      row - the number of row
      Returns:
      true if the row can be fixed.
    • areRowsFixable

      public final boolean areRowsFixable(List<? extends Integer> list)
      Indicates whether a List of rows can be fixed or not. A set of rows cannot be fixed if any cell inside these rows has a row span superior to the number of fixed rows.
      Parameters:
      list - List of rows indices
      Returns:
      true if the List of row can be fixed together.
    • isRowFixingEnabled

      public final boolean isRowFixingEnabled()
      Return whether changes to Fixed rows are enabled.
      Returns:
      whether changes to Fixed rows are enabled.
    • setRowFixingEnabled

      public final void setRowFixingEnabled(boolean b)
      If set to true, user will be allowed to fix and unfix the rows.
      Parameters:
      b - If set to true, user will be allowed to fix and unfix the rows
    • rowFixingEnabledProperty

      public final ReadOnlyBooleanProperty rowFixingEnabledProperty()
      Return the Boolean property associated with the allowance of fixing or unfixing some rows.
      See Also:
    • getFixedColumns

      public final ObservableList<TableColumn> getFixedColumns()
      You can fix or unfix a column by modifying this list.
      Returns:
      an ObservableList of the fixed columns.
    • isColumnFixable

      public final boolean isColumnFixable(int columnIndex)
      Indicate whether this column can be fixed or not.
      Parameters:
      columnIndex - the number of column
      Returns:
      true if the column if fixable
    • isColumnFixingEnabled

      public final boolean isColumnFixingEnabled()
      Return whether changes to Fixed columns are enabled.
      Returns:
      whether changes to Fixed columns are enabled.
    • setColumnFixingEnabled

      public final void setColumnFixingEnabled(boolean b)
      If set to true, user will be allowed to fix and unfix the columns.
      Parameters:
      b - If set to true, user will be allowed to fix and unfix the columns
    • columnFixingEnabledProperty

      public final ReadOnlyBooleanProperty columnFixingEnabledProperty()
      Return the Boolean property associated with the allowance of fixing or unfixing some columns.
      See Also:
    • setRowHeaderVisible

      public final void setRowHeaderVisible(boolean b)
      Activate and deactivate the row header.
      Parameters:
      b - boolean to show or hide the header
    • isRowHeaderVisible

      public final boolean isRowHeaderVisible()
      Return if the row header is showing.
      Returns:
      a boolean telling if the row header is being shown
    • rowHeaderVisibleProperty

      public final BooleanProperty rowHeaderVisibleProperty()
      BooleanProperty associated with the row Header.
      See Also:
    • rowHeaderWidthProperty

      public final DoubleProperty rowHeaderWidthProperty()
      This DoubleProperty represents the with of the rowHeader. This is just representing the width of the Labels.
      Returns:
      A DoubleProperty.
    • setRowHeaderWidth

      public final void setRowHeaderWidth(double value)
      Specify a new width for the row header.
      Parameters:
      value - the new width
    • getRowHeaderWidth

      public final double getRowHeaderWidth()
      Returns:
      the current width of the row header.
    • setRowHeader

      public final void setRowHeader(TableColumn<S,?> value)
      Sets the value of the property rowHeader.
      Property description:
      The row header property wraps a TableColumn that can be used to render the row header. By default, if this property is not set, a TableColumn will be used to render the number of row, starting from 1.
    • getRowHeader

      public final TableColumn<S,?> getRowHeader()
      Gets the value of the property rowHeader.
      Property description:
      The row header property wraps a TableColumn that can be used to render the row header. By default, if this property is not set, a TableColumn will be used to render the number of row, starting from 1.
    • rowHeaderProperty

      public final ObjectProperty<TableColumn<S,?>> rowHeaderProperty()
      The row header property wraps a TableColumn that can be used to render the row header. By default, if this property is not set, a TableColumn will be used to render the number of row, starting from 1.
      See Also:
    • setRowHeaderContextMenuFactory

      public final void setRowHeaderContextMenuFactory(BiFunction<Integer,S,ContextMenu> value)
      Sets the value of the property rowHeaderContextMenuFactory.
      Property description:
      An object property of a BiFunction that can be used to define the context menu of each row of the row header. See RowFixAction.
    • getRowHeaderContextMenuFactory

      public final BiFunction<Integer,S,ContextMenu> getRowHeaderContextMenuFactory()
      Gets the value of the property rowHeaderContextMenuFactory.
      Property description:
      An object property of a BiFunction that can be used to define the context menu of each row of the row header. See RowFixAction.
    • rowHeaderContextMenuFactoryProperty

      public final ObjectProperty<BiFunction<Integer,S,ContextMenu>> rowHeaderContextMenuFactoryProperty()
      An object property of a BiFunction that can be used to define the context menu of each row of the row header. See RowFixAction.
      See Also:
    • setSouthHeaderBlended

      public final void setSouthHeaderBlended(boolean value)
      Sets the value of the property southHeaderBlended.
      Property description:
      This property allows the developer to blend the south table header row with the regular table header row, so for each column, the regular header and the south table column header look like a single one.
    • isSouthHeaderBlended

      public final boolean isSouthHeaderBlended()
      Gets the value of the property southHeaderBlended.
      Property description:
      This property allows the developer to blend the south table header row with the regular table header row, so for each column, the regular header and the south table column header look like a single one.
    • southHeaderBlendedProperty

      public final BooleanProperty southHeaderBlendedProperty()
      This property allows the developer to blend the south table header row with the regular table header row, so for each column, the regular header and the south table column header look like a single one.
      See Also:
    • getSpanType

      public TableView2.SpanType getSpanType(int rowIndex, int modelColumn)
      Return the TableView2.SpanType of a cell. This is used internally by the TableView2 but some users may find it useful.
      Parameters:
      rowIndex - the number of row
      modelColumn - the number of column
      Returns:
      The TableView2.SpanType of a cell
    • sort

      public void sort()
      Overrides TableView.sort() in order to fire custom sort events when sorting starts and finishes. See TableView.sort() for more details about calling directly this method.
      Overrides:
      sort in class TableView<S>
    • createDefaultSkin

      protected Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class TableView<S>
    • getUserAgentStylesheet

      public String getUserAgentStylesheet()
      Overrides:
      getUserAgentStylesheet in class Region