- java.lang.Object
-
- javafx.scene.Node
-
- javafx.scene.Parent
-
- javafx.scene.layout.Region
-
- javafx.scene.control.Control
-
- javafx.scene.control.TableView<S>
-
- org.controlsfx.control.tableview2.TableView2<S>
-
- Type Parameters:
S- The type of the objects contained within the TableView2 items list.
- All Implemented Interfaces:
javafx.css.Styleable,javafx.event.EventTarget,javafx.scene.control.Skinnable
- Direct Known Subclasses:
FilteredTableView
public class TableView2<S> extends javafx.scene.control.TableView<S>The TableView2 is an advanced JavaFXTableViewcontrol, 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
TableView2so that they are always visible on screen. - Columns can be fixed to the left of the
TableView2so 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.
FilteredTableViewis a subclass of TableView2 with extended filtering options
Fixing Rows and Columns
Rows and columns can be fixed using dedicated actions likeColumnFixActionandRowFixAction. When fixed, the header's background will show a darker color. For instance, these actions can be attached to aContextMenuthat can be installed to the row header cells withrowHeaderContextMenuFactory.
You have also the possibility to fix them manually by adding and removing items fromgetFixedRows()andgetFixedColumns(). But you are strongly advised to check if it's possible to do so withisColumnFixable(int)for the fixed columns and withisRowFixable(int)for the fixed rows.
If you want to fix several rows or columns together, you can callareRowsFixable(List)orareTableViewColumnsFixable(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 providedsetRowHeaderVisible(boolean). By default the row header will show the row index, but you can set the content withsetRowHeader(TableColumn).Cell editing
Two specialized cell factories are availableTextField2TableCellandComboBox2TableCell, providing support for commit on focus lost.Filtering options
While filtering can be implemented as in a regular JavaFX TableView control, seeFilteredTableViewfor extended filtering options.Features not supported
Cell spanning is not supported yet.Sample
Let's provide the underlying data model, based on a
Personclass.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
columnsto 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);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTableView2.SpanTypeThe SpanType describes in which state each cell can be.
-
Constructor Summary
Constructors Constructor Description TableView2()Creates a TableView2 control with no content.TableView2(javafx.collections.ObservableList<S> items)Creates a TableView2 with the content provided in the items ObservableList.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanareRowsFixable(List<? extends Integer> list)Indicates whether a List of rows can be fixed or not.javafx.beans.property.ReadOnlyBooleanPropertycolumnFixingEnabledProperty()Return the Boolean property associated with the allowance of fixing or unfixing some columns.protected javafx.scene.control.Skin<?>createDefaultSkin()intgetColumnSpan(javafx.scene.control.TablePosition<?,?> pos)Return the current column span.javafx.collections.ObservableList<javafx.scene.control.TableColumn>getFixedColumns()You can fix or unfix a column by modifying this list.javafx.collections.ObservableList<Integer>getFixedRows()You can fix or unfix a row by modifying this list.javafx.scene.control.TableColumn<S,?>getRowHeader()BiFunction<Integer,S,javafx.scene.control.ContextMenu>getRowHeaderContextMenuFactory()doublegetRowHeaderWidth()intgetRowSpan(javafx.scene.control.TablePosition<?,?> pos, int index)Return the current row span at the given position in the Table.TableView2.SpanTypegetSpanType(int rowIndex, int modelColumn)Return theTableView2.SpanTypeof a cell.StringgetUserAgentStylesheet()booleanisColumnFixable(int columnIndex)Indicate whether this column can be fixed or not.booleanisColumnFixingEnabled()Return whether changes to Fixed columns are enabled.booleanisRowFixable(int row)Indicate whether a row can be fixed or not.booleanisRowFixingEnabled()Return whether changes to Fixed rows are enabled.booleanisRowHeaderVisible()Return if the row header is showing.booleanisSouthHeaderBlended()javafx.beans.property.ReadOnlyBooleanPropertyrowFixingEnabledProperty()Return the Boolean property associated with the allowance of fixing or unfixing some rows.javafx.beans.property.ObjectProperty<BiFunction<Integer,S,javafx.scene.control.ContextMenu>>rowHeaderContextMenuFactoryProperty()javafx.beans.property.ObjectProperty<javafx.scene.control.TableColumn<S,?>>rowHeaderProperty()javafx.beans.property.BooleanPropertyrowHeaderVisibleProperty()BooleanProperty associated with the row Header.javafx.beans.property.DoublePropertyrowHeaderWidthProperty()This DoubleProperty represents the with of the rowHeader.voidsetColumnFixingEnabled(boolean b)If set to true, user will be allowed to fix and unfix the columns.voidsetRowFixingEnabled(boolean b)If set to true, user will be allowed to fix and unfix the rows.voidsetRowHeader(javafx.scene.control.TableColumn<S,?> value)voidsetRowHeaderContextMenuFactory(BiFunction<Integer,S,javafx.scene.control.ContextMenu> value)voidsetRowHeaderVisible(boolean b)Activate and deactivate the row header.voidsetRowHeaderWidth(double value)Specify a new width for the row header.voidsetSouthHeaderBlended(boolean value)voidsort()OverridesTableView.sort()in order to fire custom sort events when sorting starts and finishes.javafx.beans.property.BooleanPropertysouthHeaderBlendedProperty()-
Methods inherited from class javafx.scene.control.TableView
columnResizePolicyProperty, comparatorProperty, edit, editableProperty, editingCellProperty, fixedCellSizeProperty, focusModelProperty, getClassCssMetaData, getColumnResizePolicy, getColumns, getComparator, getControlCssMetaData, getEditingCell, getFixedCellSize, getFocusModel, getItems, getOnScrollTo, getOnScrollToColumn, getOnSort, getPlaceholder, getRowFactory, getSelectionModel, getSortOrder, getSortPolicy, getVisibleLeafColumn, getVisibleLeafColumns, getVisibleLeafIndex, isEditable, isTableMenuButtonVisible, itemsProperty, onScrollToColumnProperty, onScrollToProperty, onSortProperty, placeholderProperty, queryAccessibleAttribute, refresh, resizeColumn, rowFactoryProperty, scrollTo, scrollTo, scrollToColumn, scrollToColumnIndex, selectionModelProperty, setColumnResizePolicy, setEditable, setFixedCellSize, setFocusModel, setItems, setOnScrollTo, setOnScrollToColumn, setOnSort, setPlaceholder, setRowFactory, setSelectionModel, setSortPolicy, setTableMenuButtonVisible, sortPolicyProperty, tableMenuButtonVisibleProperty
-
Methods inherited from class javafx.scene.control.Control
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, executeAccessibleAction, getBaselineOffset, getContextMenu, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty
-
Methods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
-
Methods inherited from class javafx.scene.Parent
getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
-
Methods inherited from class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
-
-
-
-
Constructor Detail
-
TableView2
public TableView2()
Creates a TableView2 control with no content.
-
TableView2
public TableView2(javafx.collections.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 Detail
-
getRowSpan
public int getRowSpan(javafx.scene.control.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- theTablePositionindex- the index- Returns:
- the current row span for the given cell.
-
getColumnSpan
public int getColumnSpan(javafx.scene.control.TablePosition<?,?> pos)
Return the current column span.- Parameters:
pos- TheTablePosition- Returns:
- the current column span of a Cell.
-
getFixedRows
public final javafx.collections.ObservableList<Integer> getFixedRows()
You can fix or unfix a row by modifying this list. CallisRowFixable(int)before trying to fix a row. SeeTableView2description 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 withgetFixedRows(). 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 javafx.beans.property.ReadOnlyBooleanProperty rowFixingEnabledProperty()
Return the Boolean property associated with the allowance of fixing or unfixing some rows.- Returns:
- the Boolean property associated with the allowance of fixing or unfixing some rows.
-
getFixedColumns
public final javafx.collections.ObservableList<javafx.scene.control.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 javafx.beans.property.ReadOnlyBooleanProperty columnFixingEnabledProperty()
Return the Boolean property associated with the allowance of fixing or unfixing some columns.- Returns:
- the Boolean property associated with the allowance of fixing or unfixing some columns.
-
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 javafx.beans.property.BooleanProperty rowHeaderVisibleProperty()
BooleanProperty associated with the row Header.- Returns:
- the BooleanProperty associated with the row header.
-
rowHeaderWidthProperty
public final javafx.beans.property.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(javafx.scene.control.TableColumn<S,?> value)
-
getRowHeader
public final javafx.scene.control.TableColumn<S,?> getRowHeader()
-
rowHeaderProperty
public final javafx.beans.property.ObjectProperty<javafx.scene.control.TableColumn<S,?>> rowHeaderProperty()
-
setRowHeaderContextMenuFactory
public final void setRowHeaderContextMenuFactory(BiFunction<Integer,S,javafx.scene.control.ContextMenu> value)
-
getRowHeaderContextMenuFactory
public final BiFunction<Integer,S,javafx.scene.control.ContextMenu> getRowHeaderContextMenuFactory()
-
rowHeaderContextMenuFactoryProperty
public final javafx.beans.property.ObjectProperty<BiFunction<Integer,S,javafx.scene.control.ContextMenu>> rowHeaderContextMenuFactoryProperty()
-
setSouthHeaderBlended
public final void setSouthHeaderBlended(boolean value)
-
isSouthHeaderBlended
public final boolean isSouthHeaderBlended()
-
southHeaderBlendedProperty
public final javafx.beans.property.BooleanProperty southHeaderBlendedProperty()
-
getSpanType
public TableView2.SpanType getSpanType(int rowIndex, int modelColumn)
Return theTableView2.SpanTypeof a cell. This is used internally by the TableView2 but some users may find it useful.- Parameters:
rowIndex- the number of rowmodelColumn- the number of column- Returns:
- The
TableView2.SpanTypeof a cell
-
sort
public void sort()
OverridesTableView.sort()in order to fire custom sort events when sorting starts and finishes. SeeTableView.sort()for more details about calling directly this method.- Overrides:
sortin classjavafx.scene.control.TableView<S>
-
createDefaultSkin
protected javafx.scene.control.Skin<?> createDefaultSkin()
- Overrides:
createDefaultSkinin classjavafx.scene.control.TableView<S>
-
getUserAgentStylesheet
public String getUserAgentStylesheet()
- Overrides:
getUserAgentStylesheetin classjavafx.scene.layout.Region
-
-