Class TableColumnBase<S,​T>

java.lang.Object
javafx.scene.control.TableColumnBase<S,​T>
Type Parameters:
S - The type of the UI control (e.g. the type of the 'row').
T - The type of the content in all cells in this table column.
All Implemented Interfaces:
Styleable, EventTarget
Direct Known Subclasses:
TableColumn, TreeTableColumn

@IDProperty("id")
public abstract class TableColumnBase<S,​T>
extends Object
implements EventTarget, Styleable
Table-like controls (such as TableView and TreeTableView) are made up of zero or more instances of a concrete TableColumnBase subclass (TableColumn and TreeTableColumn, respectively). Each table column in a table is responsible for displaying (and editing) the contents of that column. As well as being responsible for displaying and editing data for a single column, a table column also contains the necessary properties to: When instantiating a concrete subclass of TableColumnBase, perhaps the two most important properties to set are the column text (what to show in the column header area), and the column cell value factory (which is used to populate individual cells in the column). Refer to the class documentation for TableColumn and TreeTableColumn for more information.
Since:
JavaFX 8.0
See Also:
TableColumn, TreeTableColumn, TablePositionBase
  • Property Details

    • text

      public final StringProperty textProperty
      This is the text to show in the header for this column.
      See Also:
      getText(), setText(String)
    • visible

      public final BooleanProperty visibleProperty
      Toggling this will immediately toggle the visibility of this column, and all children columns.
      See Also:
      isVisible(), setVisible(boolean)
    • parentColumn

      public final ReadOnlyObjectProperty<TableColumnBase<S,​?>> parentColumnProperty
      This read-only property will always refer to the parent of this column, in the situation where nested columns are being used.

      In the currently existing subclasses, to create a nested column is simply a matter of placing the relevant TableColumnBase instances inside the columns ObservableList (for example, see getColumns() and getColumns().

      See Also:
      getParentColumn()
    • contextMenu

      public final ObjectProperty<ContextMenu> contextMenuProperty
      This menu will be shown whenever the user right clicks within the header area of this TableColumnBase.
      See Also:
      getContextMenu(), setContextMenu(ContextMenu)
    • id

      public final StringProperty idProperty
      The id of this TableColumnBase. This simple string identifier is useful for finding a specific TableColumnBase within a UI control that uses TableColumnBase instances. The default value is null.
      Default value:
      null
      See Also:
      Styleable.getId(), setId(String)
    • style

      public final StringProperty styleProperty
      A string representation of the CSS style associated with this TableColumnBase instance. This is analogous to the "style" attribute of an HTML element. Note that, like the HTML style attribute, this variable contains style properties and values and not the selector portion of a style rule.

      Parsing this style might not be supported on some limited platforms. It is recommended to use a standalone CSS file instead.

      Default value:
      empty string
      See Also:
      Styleable.getStyle(), setStyle(String)
    • graphic

      public final ObjectProperty<Node> graphicProperty

      The graphic to show in the table column to allow the user to indicate graphically what is in the column.

      See Also:
      getGraphic(), setGraphic(Node)
    • sortNode

      public final ObjectProperty<Node> sortNodeProperty

      The node to use as the "sort arrow", shown to the user in situations where the table column is part of the sort order. It may be the only item in the sort order, or it may be a secondary, tertiary, or latter sort item, and the node should reflect this visually. This is only used in the case of the table column being in the sort order (refer to, for example, TableView.getSortOrder() and TreeTableView.getSortOrder()). If not specified, the table column skin implementation is responsible for providing a default sort node.

      The sort node is commonly seen represented as a triangle that rotates on screen to indicate whether the table column is part of the sort order, and if so, whether the sort is ascending or descending, and what position in the sort order it is in.

      See Also:
      getSortNode(), setSortNode(Node)
    • width

      public final ReadOnlyDoubleProperty widthProperty
      The width of this column. Modifying this will result in the column width adjusting visually. It is recommended to not bind this property to an external property, as that will result in the column width not being adjustable by the user through dragging the left and right borders of column headers.
      See Also:
      getWidth()
    • minWidth

      public final DoubleProperty minWidthProperty
      The minimum width the table column is permitted to be resized to.
      See Also:
      getMinWidth(), setMinWidth(double)
    • prefWidth

      public final DoubleProperty prefWidthProperty
      The preferred width of the TableColumn.
      See Also:
      getPrefWidth(), setPrefWidth(double)
    • maxWidth

      public final DoubleProperty maxWidthProperty
      The maximum width the table column is permitted to be resized to.
      See Also:
      getMaxWidth(), setMaxWidth(double)
    • resizable

      public final BooleanProperty resizableProperty
      Used to indicate whether the width of this column can change. It is up to the resizing policy to enforce this however.
      See Also:
      isResizable(), setResizable(boolean)
    • sortable

      public final BooleanProperty sortableProperty

      A boolean property to toggle on and off the 'sortability' of this column. When this property is true, this column can be included in sort operations. If this property is false, it will not be included in sort operations, even if it is contained within the sort order list of the underlying UI control (e.g. TableView.getSortOrder() or TreeTableView.getSortOrder()).

      For example, iIf a TableColumn instance is contained within the TableView sortOrder ObservableList, and its sortable property toggles state, it will force the TableView to perform a sort, as it is likely the view will need updating.

      See Also:
      isSortable(), setSortable(boolean)
    • reorderable

      public final BooleanProperty reorderableProperty
      A boolean property to toggle on and off the 'reorderability' of this column (with drag and drop - reordering by modifying the appropriate columns list is always allowed). When this property is true, this column can be reordered by users simply by dragging and dropping the columns into their desired positions. When this property is false, this ability to drag and drop columns is not available.
      Since:
      9
      See Also:
      isReorderable(), setReorderable(boolean)
    • comparator

      public final ObjectProperty<Comparator<T>> comparatorProperty
      Comparator function used when sorting this table column. The two Objects given as arguments are the cell data for two individual cells in this column.
      See Also:
      getComparator(), setComparator(Comparator)
    • editable

      public final BooleanProperty editableProperty
      Specifies whether this table column allows editing. This, unlike TableView.editableProperty() and TreeTableView.editableProperty(), is true by default.
      See Also:
      isEditable(), setEditable(boolean)
  • Field Details

  • Constructor Details

    • TableColumnBase

      protected TableColumnBase()
      Creates a default TableColumn with default cell factory, comparator, and onEditCommit implementation.
    • TableColumnBase

      protected TableColumnBase​(String text)
      Creates a TableColumn with the text set to the provided string, with default cell factory, comparator, and onEditCommit implementation.
      Parameters:
      text - The string to show when the TableColumn is placed within the TableView.
  • Method Details

    • textProperty

      public final StringProperty textProperty()
      This is the text to show in the header for this column.
      See Also:
      getText(), setText(String)
    • setText

      public final void setText​(String value)
      Sets the value of the property text.
      Property description:
      This is the text to show in the header for this column.
    • getText

      public final String getText()
      Gets the value of the property text.
      Property description:
      This is the text to show in the header for this column.
    • setVisible

      public final void setVisible​(boolean value)
      Sets the value of the property visible.
      Property description:
      Toggling this will immediately toggle the visibility of this column, and all children columns.
    • isVisible

      public final boolean isVisible()
      Gets the value of the property visible.
      Property description:
      Toggling this will immediately toggle the visibility of this column, and all children columns.
    • visibleProperty

      public final BooleanProperty visibleProperty()
      Toggling this will immediately toggle the visibility of this column, and all children columns.
      See Also:
      isVisible(), setVisible(boolean)
    • getParentColumn

      public final TableColumnBase<S,​?> getParentColumn()
      Gets the value of the property parentColumn.
      Property description:
      This read-only property will always refer to the parent of this column, in the situation where nested columns are being used.

      In the currently existing subclasses, to create a nested column is simply a matter of placing the relevant TableColumnBase instances inside the columns ObservableList (for example, see getColumns() and getColumns().

    • parentColumnProperty

      public final ReadOnlyObjectProperty<TableColumnBase<S,​?>> parentColumnProperty()
      This read-only property will always refer to the parent of this column, in the situation where nested columns are being used.

      In the currently existing subclasses, to create a nested column is simply a matter of placing the relevant TableColumnBase instances inside the columns ObservableList (for example, see getColumns() and getColumns().

      See Also:
      getParentColumn()
    • setContextMenu

      public final void setContextMenu​(ContextMenu value)
      Sets the value of the property contextMenu.
      Property description:
      This menu will be shown whenever the user right clicks within the header area of this TableColumnBase.
    • getContextMenu

      public final ContextMenu getContextMenu()
      Gets the value of the property contextMenu.
      Property description:
      This menu will be shown whenever the user right clicks within the header area of this TableColumnBase.
    • contextMenuProperty

      public final ObjectProperty<ContextMenu> contextMenuProperty()
      This menu will be shown whenever the user right clicks within the header area of this TableColumnBase.
      See Also:
      getContextMenu(), setContextMenu(ContextMenu)
    • setId

      public final void setId​(String value)
      Sets the value of the property id.
      Property description:
      The id of this TableColumnBase. This simple string identifier is useful for finding a specific TableColumnBase within a UI control that uses TableColumnBase instances. The default value is null.
      Default value:
      null
    • idProperty

      public final StringProperty idProperty()
      The id of this TableColumnBase. This simple string identifier is useful for finding a specific TableColumnBase within a UI control that uses TableColumnBase instances. The default value is null.
      Default value:
      null
      See Also:
      Styleable.getId(), setId(String)
    • setStyle

      public final void setStyle​(String value)
      Sets the value of the property style.
      Property description:
      A string representation of the CSS style associated with this TableColumnBase instance. This is analogous to the "style" attribute of an HTML element. Note that, like the HTML style attribute, this variable contains style properties and values and not the selector portion of a style rule.

      Parsing this style might not be supported on some limited platforms. It is recommended to use a standalone CSS file instead.

      Default value:
      empty string
    • styleProperty

      public final StringProperty styleProperty()
      A string representation of the CSS style associated with this TableColumnBase instance. This is analogous to the "style" attribute of an HTML element. Note that, like the HTML style attribute, this variable contains style properties and values and not the selector portion of a style rule.

      Parsing this style might not be supported on some limited platforms. It is recommended to use a standalone CSS file instead.

      Default value:
      empty string
      See Also:
      Styleable.getStyle(), setStyle(String)
    • getStyleClass

      public ObservableList<String> getStyleClass()
      A list of String identifiers which can be used to logically group Nodes, specifically for an external style engine. This variable is analogous to the "class" attribute on an HTML element and, as such, each element of the list is a style class to which this Node belongs.
      Specified by:
      getStyleClass in interface Styleable
      Returns:
      a list of String identifiers which can be used to logically group Nodes, specifically for an external style engine
      See Also:
      CSS3 class selectors
    • setGraphic

      public final void setGraphic​(Node value)
      Sets the value of the property graphic.
      Property description:

      The graphic to show in the table column to allow the user to indicate graphically what is in the column.

    • getGraphic

      public final Node getGraphic()
      Gets the value of the property graphic.
      Property description:

      The graphic to show in the table column to allow the user to indicate graphically what is in the column.

    • graphicProperty

      public final ObjectProperty<Node> graphicProperty()

      The graphic to show in the table column to allow the user to indicate graphically what is in the column.

      See Also:
      getGraphic(), setGraphic(Node)
    • setSortNode

      public final void setSortNode​(Node value)
      Sets the value of the property sortNode.
      Property description:

      The node to use as the "sort arrow", shown to the user in situations where the table column is part of the sort order. It may be the only item in the sort order, or it may be a secondary, tertiary, or latter sort item, and the node should reflect this visually. This is only used in the case of the table column being in the sort order (refer to, for example, TableView.getSortOrder() and TreeTableView.getSortOrder()). If not specified, the table column skin implementation is responsible for providing a default sort node.

      The sort node is commonly seen represented as a triangle that rotates on screen to indicate whether the table column is part of the sort order, and if so, whether the sort is ascending or descending, and what position in the sort order it is in.

    • getSortNode

      public final Node getSortNode()
      Gets the value of the property sortNode.
      Property description:

      The node to use as the "sort arrow", shown to the user in situations where the table column is part of the sort order. It may be the only item in the sort order, or it may be a secondary, tertiary, or latter sort item, and the node should reflect this visually. This is only used in the case of the table column being in the sort order (refer to, for example, TableView.getSortOrder() and TreeTableView.getSortOrder()). If not specified, the table column skin implementation is responsible for providing a default sort node.

      The sort node is commonly seen represented as a triangle that rotates on screen to indicate whether the table column is part of the sort order, and if so, whether the sort is ascending or descending, and what position in the sort order it is in.

    • sortNodeProperty

      public final ObjectProperty<Node> sortNodeProperty()

      The node to use as the "sort arrow", shown to the user in situations where the table column is part of the sort order. It may be the only item in the sort order, or it may be a secondary, tertiary, or latter sort item, and the node should reflect this visually. This is only used in the case of the table column being in the sort order (refer to, for example, TableView.getSortOrder() and TreeTableView.getSortOrder()). If not specified, the table column skin implementation is responsible for providing a default sort node.

      The sort node is commonly seen represented as a triangle that rotates on screen to indicate whether the table column is part of the sort order, and if so, whether the sort is ascending or descending, and what position in the sort order it is in.

      See Also:
      getSortNode(), setSortNode(Node)
    • widthProperty

      public final ReadOnlyDoubleProperty widthProperty()
      The width of this column. Modifying this will result in the column width adjusting visually. It is recommended to not bind this property to an external property, as that will result in the column width not being adjustable by the user through dragging the left and right borders of column headers.
      See Also:
      getWidth()
    • getWidth

      public final double getWidth()
      Gets the value of the property width.
      Property description:
      The width of this column. Modifying this will result in the column width adjusting visually. It is recommended to not bind this property to an external property, as that will result in the column width not being adjustable by the user through dragging the left and right borders of column headers.
    • setMinWidth

      public final void setMinWidth​(double value)
      Sets the value of the property minWidth.
      Property description:
      The minimum width the table column is permitted to be resized to.
    • getMinWidth

      public final double getMinWidth()
      Gets the value of the property minWidth.
      Property description:
      The minimum width the table column is permitted to be resized to.
    • minWidthProperty

      public final DoubleProperty minWidthProperty()
      The minimum width the table column is permitted to be resized to.
      See Also:
      getMinWidth(), setMinWidth(double)
    • prefWidthProperty

      public final DoubleProperty prefWidthProperty()
      The preferred width of the TableColumn.
      See Also:
      getPrefWidth(), setPrefWidth(double)
    • setPrefWidth

      public final void setPrefWidth​(double value)
      Sets the value of the property prefWidth.
      Property description:
      The preferred width of the TableColumn.
    • getPrefWidth

      public final double getPrefWidth()
      Gets the value of the property prefWidth.
      Property description:
      The preferred width of the TableColumn.
    • maxWidthProperty

      public final DoubleProperty maxWidthProperty()
      The maximum width the table column is permitted to be resized to.
      See Also:
      getMaxWidth(), setMaxWidth(double)
    • setMaxWidth

      public final void setMaxWidth​(double value)
      Sets the value of the property maxWidth.
      Property description:
      The maximum width the table column is permitted to be resized to.
    • getMaxWidth

      public final double getMaxWidth()
      Gets the value of the property maxWidth.
      Property description:
      The maximum width the table column is permitted to be resized to.
    • resizableProperty

      public final BooleanProperty resizableProperty()
      Used to indicate whether the width of this column can change. It is up to the resizing policy to enforce this however.
      See Also:
      isResizable(), setResizable(boolean)
    • setResizable

      public final void setResizable​(boolean value)
      Sets the value of the property resizable.
      Property description:
      Used to indicate whether the width of this column can change. It is up to the resizing policy to enforce this however.
    • isResizable

      public final boolean isResizable()
      Gets the value of the property resizable.
      Property description:
      Used to indicate whether the width of this column can change. It is up to the resizing policy to enforce this however.
    • sortableProperty

      public final BooleanProperty sortableProperty()

      A boolean property to toggle on and off the 'sortability' of this column. When this property is true, this column can be included in sort operations. If this property is false, it will not be included in sort operations, even if it is contained within the sort order list of the underlying UI control (e.g. TableView.getSortOrder() or TreeTableView.getSortOrder()).

      For example, iIf a TableColumn instance is contained within the TableView sortOrder ObservableList, and its sortable property toggles state, it will force the TableView to perform a sort, as it is likely the view will need updating.

      See Also:
      isSortable(), setSortable(boolean)
    • setSortable

      public final void setSortable​(boolean value)
      Sets the value of the property sortable.
      Property description:

      A boolean property to toggle on and off the 'sortability' of this column. When this property is true, this column can be included in sort operations. If this property is false, it will not be included in sort operations, even if it is contained within the sort order list of the underlying UI control (e.g. TableView.getSortOrder() or TreeTableView.getSortOrder()).

      For example, iIf a TableColumn instance is contained within the TableView sortOrder ObservableList, and its sortable property toggles state, it will force the TableView to perform a sort, as it is likely the view will need updating.

    • isSortable

      public final boolean isSortable()
      Gets the value of the property sortable.
      Property description:

      A boolean property to toggle on and off the 'sortability' of this column. When this property is true, this column can be included in sort operations. If this property is false, it will not be included in sort operations, even if it is contained within the sort order list of the underlying UI control (e.g. TableView.getSortOrder() or TreeTableView.getSortOrder()).

      For example, iIf a TableColumn instance is contained within the TableView sortOrder ObservableList, and its sortable property toggles state, it will force the TableView to perform a sort, as it is likely the view will need updating.

    • reorderableProperty

      public final BooleanProperty reorderableProperty()
      A boolean property to toggle on and off the 'reorderability' of this column (with drag and drop - reordering by modifying the appropriate columns list is always allowed). When this property is true, this column can be reordered by users simply by dragging and dropping the columns into their desired positions. When this property is false, this ability to drag and drop columns is not available.
      Since:
      9
      See Also:
      isReorderable(), setReorderable(boolean)
    • setReorderable

      public final void setReorderable​(boolean value)
      Sets the value of the property reorderable.
      Property description:
      A boolean property to toggle on and off the 'reorderability' of this column (with drag and drop - reordering by modifying the appropriate columns list is always allowed). When this property is true, this column can be reordered by users simply by dragging and dropping the columns into their desired positions. When this property is false, this ability to drag and drop columns is not available.
      Since:
      9
    • isReorderable

      public final boolean isReorderable()
      Gets the value of the property reorderable.
      Property description:
      A boolean property to toggle on and off the 'reorderability' of this column (with drag and drop - reordering by modifying the appropriate columns list is always allowed). When this property is true, this column can be reordered by users simply by dragging and dropping the columns into their desired positions. When this property is false, this ability to drag and drop columns is not available.
      Since:
      9
    • comparatorProperty

      public final ObjectProperty<Comparator<T>> comparatorProperty()
      Comparator function used when sorting this table column. The two Objects given as arguments are the cell data for two individual cells in this column.
      See Also:
      getComparator(), setComparator(Comparator)
    • setComparator

      public final void setComparator​(Comparator<T> value)
      Sets the value of the property comparator.
      Property description:
      Comparator function used when sorting this table column. The two Objects given as arguments are the cell data for two individual cells in this column.
    • getComparator

      public final Comparator<T> getComparator()
      Gets the value of the property comparator.
      Property description:
      Comparator function used when sorting this table column. The two Objects given as arguments are the cell data for two individual cells in this column.
    • setEditable

      public final void setEditable​(boolean value)
      Sets the value of the property editable.
      Property description:
      Specifies whether this table column allows editing. This, unlike TableView.editableProperty() and TreeTableView.editableProperty(), is true by default.
    • isEditable

      public final boolean isEditable()
      Gets the value of the property editable.
      Property description:
      Specifies whether this table column allows editing. This, unlike TableView.editableProperty() and TreeTableView.editableProperty(), is true by default.
    • editableProperty

      public final BooleanProperty editableProperty()
      Specifies whether this table column allows editing. This, unlike TableView.editableProperty() and TreeTableView.editableProperty(), is true by default.
      See Also:
      isEditable(), setEditable(boolean)
    • getProperties

      public final ObservableMap<Object,​Object> getProperties()
      Returns an observable map of properties on this table column for use primarily by application developers.
      Returns:
      an observable map of properties on this table column for use primarily by application developers
    • hasProperties

      public boolean hasProperties()
      Tests if this table column has properties.
      Returns:
      true if node has properties.
    • setUserData

      public void setUserData​(Object value)
      Convenience method for setting a single Object property that can be retrieved at a later date. This is functionally equivalent to calling the getProperties().put(Object key, Object value) method. This can later be retrieved by calling getUserData().
      Parameters:
      value - The value to be stored - this can later be retrieved by calling getUserData().
    • getUserData

      public Object getUserData()
      Returns a previously set Object property, or null if no such property has been set using the setUserData(java.lang.Object) method.
      Returns:
      The Object that was previously set, or null if no property has been set or if null was set.
    • getColumns

      public abstract ObservableList<? extends TableColumnBase<S,​?>> getColumns()
      This enables support for nested columns, which can be useful to group together related data. For example, we may have a 'Name' column with two nested columns for 'First' and 'Last' names.

      This has no impact on the table as such - all column indices point to the leaf columns only, and it isn't possible to sort using the parent column, just the leaf columns. In other words, this is purely a visual feature.

      Returns:
      An ObservableList containing TableColumnBase instances (or subclasses) that are the children of this TableColumnBase. If these children TableColumnBase instances are set as visible, they will appear beneath this table column.
    • getCellData

      public final T getCellData​(int index)
      Returns the actual value for a cell at a given row index (and which belongs to this table column).
      Parameters:
      index - The row index for which the data is required.
      Returns:
      The data that belongs to the cell at the intersection of the given row index and the table column that this method is called on.
    • getCellData

      public final T getCellData​(S item)
      Returns the actual value for a cell from the given item.
      Parameters:
      item - The item from which a value of type T should be extracted.
      Returns:
      The data that should be used in a specific cell in this column, based on the item passed in as an argument.
    • getCellObservableValue

      public abstract ObservableValue<T> getCellObservableValue​(int index)
      Attempts to return an ObservableValue<T> for the item in the given index (which is of type S). In other words, this method expects to receive an integer value that is greater than or equal to zero, and less than the size of the underlying data model. If the index is valid, this method will return an ObservableValue<T> for this specific column.

      This is achieved by calling the cell value factory, and returning whatever it returns when passed a CellDataFeatures (see, for example, the CellDataFeatures classes belonging to TableColumn and TreeTableColumn for more information).

      Parameters:
      index - The index of the item (of type S) for which an ObservableValue<T> is sought.
      Returns:
      An ObservableValue<T> for this specific table column.
    • getCellObservableValue

      public abstract ObservableValue<T> getCellObservableValue​(S item)
      Attempts to return an ObservableValue<T> for the given item (which is of type S). In other words, this method expects to receive an object from the underlying data model for the entire 'row' in the table, and it must return an ObservableValue<T> for the value in this specific column.

      This is achieved by calling the cell value factory, and returning whatever it returns when passed a CellDataFeatures (see, for example, the CellDataFeatures classes belonging to TableColumn and TreeTableColumn for more information).

      Parameters:
      item - The item (of type S) for which an ObservableValue<T> is sought.
      Returns:
      An ObservableValue<T> for this specific table column.
    • addEventHandler

      public <E extends Event> void addEventHandler​(EventType<E> eventType, EventHandler<E> eventHandler)
      Registers an event handler to this table column. The TableColumnBase class allows registration of listeners which will be notified when editing occurs. Note however that TableColumnBase is not a Node, and therefore no visual events will be fired on it.
      Type Parameters:
      E - The type of event
      Parameters:
      eventType - the type of the events to receive by the handler
      eventHandler - the handler to register
      Throws:
      NullPointerException - if the event type or handler is null
    • removeEventHandler

      public <E extends Event> void removeEventHandler​(EventType<E> eventType, EventHandler<E> eventHandler)
      Unregisters a previously registered event handler from this table column. One handler might have been registered for different event types, so the caller needs to specify the particular event type from which to unregister the handler.
      Type Parameters:
      E - The type of event
      Parameters:
      eventType - the event type from which to unregister
      eventHandler - the handler to unregister
      Throws:
      NullPointerException - if the event type or handler is null