Reputation: 2576
I want to use Table Menu Button (table.setTableMenuButtonVisible(true);
) for hiding and showing specified columns in TableView. When I deselect all columns, [+] button hides, "No columns in table" pops in and user is unable to show any column.
I've tried to prevent hiding all columns by listening to table.getVisibleLeafColumns()
and showing last hidden column, but then in ChoiceBox from Menu Button this column is unselected.
Upvotes: 3
Views: 1024
Reputation: 51525
Definitely a bug (you might consider reporting it in fx' jira). The hack-around you mentioned in your question seems to work with a little trick borrowed from Swing: delay the reversion of visibility to some future:
ListChangeListener<? super TableColumn> visibleColumnsListener = c -> {
while (c.next()) {
// very last remove
if (c.wasRemoved() && !c.wasReplaced()) {
TableColumn column = c.getRemoved().get(0);
// delay reverting visibility
Platform.runLater(() -> {
column.setVisible(true);
});
}
}
};
It may be dirtier than its analogue in Swing, though, execution of the runnable is at "some unspecified time in future" and doesn't state its relation to normal (originating from the ui) events.
Reported as RT-38907 and just fixed (was duplicate: RT-37616), should bubble up in 8u40 ea in a week or two.
Upvotes: 1