Summary
Implements a way to override the table column menu that is invoked when the table menu button is pressed.
Problem
The table column menu is a ContextMenu that shows all available columns of the table as MenuItems. A user can click on a MenuItem to make the corresponding column (in)visible and the ContextMenu closes afterwards.
One problem with this is that it is not always desired that the ContextMenu is closed after the user has clicked on a MenuItem. Especially when dealing with many columns which should be made (in)visible. Note that this is a limitation of the ContextMenu.
A developer can not solve this problem because there is no way to override the menu. It is also not possible to display this menu programmatically.
Solution
To address these issues, a new protected method showColumnMenu(MouseEvent) is implemented, which is called when the table menu button is clicked. Since this new method is protected, it can be overidden by developers. If not overridden, the known default ContextMenu is created and shown.
This gives every developer the ability to fully customize the behaviour when the table menu button is clicked. A developer can implement their own Menu if the behaviour of the ContextMenu is not desired. The method can now also be invoked programmatically.
Specification
Module: javafx.controls
Class: javafx.scene.control.skin.TableHeaderRow
/**
* Shows a menu containing all leaf columns as items.
* An item can be selected/deselected to make the corresponding column visible/invisible.
*
* @implNote This method can be overridden to create and show a custom menu.
* @param mouseEvent the {@code MouseEvent} which was generated when the table menu button was pressed
* @since 21
*/
protected void showColumnMenu(MouseEvent mouseEvent) {
...
}
- csr of
-
JDK-8091153 Customize the Table Button Menu
-
- Resolved
-