JavaFX2 TableView "Reordering columns by user at runtime." I would like to disable this feature for one specific table in my application.
Looking at the API, there is no obvious API for this. However, there are columns
-property. According to the document, he represents
TableColumns that are part of this TableView. When the user reorders the columns of the TableView, this list will be updated to display the current visual ordering.
Hoping that at least I could reset change after it occurred, I tried adding a listener to reset changes after the fact.
import javafx.application.Application; import javafx.collections.ListChangeListener; import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.stage.Stage; public class TableTest extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { TableView tableView = new TableView(); tableView.getColumns().setAll(new TableColumn(), new TableColumn()); tableView.getColumns().addListener(new ListChangeListener() { @Override public void onChanged(Change change) { if (change.wasPermutated()){ change.reset(); } } }); stage.setScene(new Scene(tableView)); stage.show(); } }
However, the listener aborts with an IllegalStateException
when I request wasPermutated
.
Is there a way to prevent reordering, or at least return it programmatically?
source share