I have noticed that sorting by column headers in the JavaFX TableView class is turned on by default.
In my case I need to have a table view that does not allow sorting by any of the columns. Does anyone know how to do this?
I have noticed that sorting by column headers in the JavaFX TableView class is turned on by default.
In my case I need to have a table view that does not allow sorting by any of the columns. Does anyone know how to do this?
If you created the table columns at own instances like this:
TableColumn<Type, Type> column = new TableColumn<>("email");
then you can easily set
column.setSortable(false);
if you use fxml, you can also set the column unsortable in fxml:
<TableColumn sortable="false"/>
/**
* Prevent a TableView from doing TableColumn sorting.
*
* @param _tableView
* @param _actionPrevent :set ON and OFF the 'Sortability' of columns.
*/
static
public < T > void preventColumnSorting( TableView< T > _tableView, boolean _actionPrevent )
{
Platform.runLater( () ->
{
_tableView.getColumns()
.forEach( column_ ->
{
column_.setSortable( ! _actionPrevent );
} );
} );
return;
}
© 2022 - 2024 — McMap. All rights reserved.