In JavaView TableView, how can I spot changes
- I. Column order [SOLVED]
- II. Column Width [Solved]
- III. Visibilty column [SOLVED]
to save them in the settings and restore them the next time you start the application?
I. Column Order
It works now. However, wasRemoved() fired when the columns are reordered, not wasPermutation() .
final List<TableColumn<MyType, ?>> unchangedColumns = Collections.unmodifiableList(new ArrayList<TableColumn<MyType, ?>>(columns)); columns.addListener(new ListChangeListener<TableColumn<MyType, ?>>() { @Override public void onChanged(ListChangeListener.Change<? extends TableColumn<MyType, ?>> change) { while (change.next()) { if (change.wasRemoved()) { ObservableList<TableColumn<MyType, ?>> columns = table.getColumns(); int[] colOrder = new int[columns.size()]; for (int i = 0; i < columns.size(); ++i) { colOrder[i] = unchangedColumns.indexOf(columns.get(i)); }
II. Column Width
It works.
for (TableColumn<MyType, ?> column: columns) { column.widthProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldWidth, Number newWidth) { logger.info("Width: " + oldWidth + " -> " + newWidth); }); }
III. Column designation
This is a trick.
for (TableColumn<MyType, ?> column: columns) { column.visibleProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observableValue, Boolean oldVisibility, Boolean newVisibility) { logger.info("Visibility: " + oldVisibility + " -> " + newVisibility); }); }
source share