RFR: 8207333: [Linux, macOS] Column sorting is triggered always after context menu request on table header

Andy Goryachev angorya at openjdk.org
Tue Apr 8 18:23:24 UTC 2025


On Tue, 8 Apr 2025 16:55:51 GMT, Martin Fox <mfox at openjdk.org> wrote:

>> Note: The JBS issue [JDK-8207333](https://bugs.openjdk.org/browse/JDK-8207333) refers to Linux, but it happens on macOS too. 
>> 
>> When a TableColumn has a ContextMenu, if the user right clicks on the tableColumnHeader, the ContextMenu shows up, but, as described on the issue, on macOS and Linux, the table gets sorted as well.
>> 
>> Currently, `TableColumnHeader#mouseReleasedHandler` checks for `MouseEvent::isPopupTriggered`, but it doesn't have a check on `mousePressed`. However,  it can be seen that a right click on the header has the following values for `MouseEvent:: isPopupTriggered` on the different platforms and mouse pressed and released events:
>> 
>> | isPopupTriggered on: | Windows  | macOS | Linux |
>> | ------------- | ------------- | ------------- | ------------- |
>> | mousePressed  | false  | true | true |
>> | mouseReleased  | true  | false | false |
>> 
>> Also, the JavaDoc for `MouseEvent::isPopupTriggered` clearly states that:
>> 
>>> **Note**: Popup menus are triggered differently on different systems. Therefore, `popupTrigger` should be checked in both `onMousePressed` and `mouseReleased` for proper cross-platform functionality.
>> 
>> Therefore, this PR adds a check to `MouseEvent::isPopupTrigger` in the mouse pressed event, that can be used later on to cancel the header sorting when the mouse released event happens.
>> 
>> Also a system test has been added. It fails on macOS and Linux, and passes on Windows before this PR, and passes on the three platforms with this PR.
>
> modules/javafx.controls/src/main/java/javafx/scene/control/skin/TableColumnHeader.java line 251:
> 
>> 249:         me.consume();
>> 250: 
>> 251:         header.getTableHeaderRow().columnDragLock = true;
> 
> On Mac a context menu can be invoked using the right button or the left button in conjunction with the Control key. In the second case the pop trigger flag will be set and the primary button will be down. If I'm reading the code correctly this could get the header stuck in column re-ordering mode.

Testing on macOS 15.3.2, it does not get stuck when using control+left-click, works as expected.

There is one (existing and unrelated) problem - if the user tries to dismiss the popup menu by clicking on the header, it dismisses the popup (correctly), but then proceeds to re-sort the table (unexpected).

One can say it works as designed, since the click falls on a header cell and the expected operation is to toggle the sorting, with the side effect of dismissing the popup.

On the other hand, Excel (both mac and windows) behaves differently - a click on the spreadsheet header dismisses the popup and does not select the column, as it normally does when no popup is present.

What do you guys think?

> modules/javafx.controls/src/main/java/javafx/scene/control/skin/TableColumnHeader.java line 275:
> 
>> 273:     private static final EventHandler<MouseEvent> mouseReleasedHandler = me -> {
>> 274:         TableColumnHeader header = (TableColumnHeader) me.getSource();
>> 275:         header.getTableHeaderRow().columnDragLock = false;
> 
> On Ubuntu 22.04 the table column header is not receiving a mouse released event if a context menu is shown. Not sure where the released event is going but it's not to any node on the primary stage. The docs are vague on this but this looks like a separate bug that's making it hard to test this PR.

what happens in the master branch (without this PR's changes)?

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1754#discussion_r2033796787
PR Review Comment: https://git.openjdk.org/jfx/pull/1754#discussion_r2033797532


More information about the openjfx-dev mailing list