RFR: 8340852: ScrollPane should not consume navigation keys when it doesn't have direct focus
John Hendrikx
jhendrikx at openjdk.org
Tue Oct 1 10:11:45 UTC 2024
On Mon, 30 Sep 2024 16:27:50 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
> I do not see much behavioral difference between controls inside a regular VBox and VBox inside a ScrollPane
>
> https://github.com/andy-goryachev-oracle/Test/blob/main/src/goryachev/research/FocusPolicyResearch.java
>
> Am I doing things wrong?
Yeah, as I explained, FX provided controls, like `ToggleButton` will capture navigation keys **before** they bubble up to `ScrollPane`. See here in `ToggleButtonBehavior`:
new KeyMapping(RIGHT, e -> traverse(e, "ToggleNext-Right")),
new KeyMapping(LEFT, e -> traverse(e, "TogglePrevious-Left")),
new KeyMapping(DOWN, e -> traverse(e, "ToggleNext-Down")),
new KeyMapping(UP, e -> traverse(e, "TogglePrevious-Up"))
So, with FX provided controls, this issue is being worked around. The controls themselves handle navigation, and so `ScrollPane` won't interfere. `ToggleButton` however is not a good example, as it has special needs for its navigation (which I hope are documented) and so is correct to override how navigation works.
Using a regular `Button` instead for your tests would be better, however this also won't work as FX provided controls are all providing their own navigation to avoid letting events bubble up to `ScrollPane`.
To make a real comparison, you need to either:
1. Remove the navigation behavior from one of the FX controls, ie. in `ButtonBehavior`, remove the line:
// add focus traversal mappings
addDefaultMapping(buttonInputMap, FocusTraversalInputMap.getFocusTraversalMappings());
2. Set a different skin on `Button` (which will also kill its standard behavior).
I'll provide an example.
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1582#issuecomment-2385376542
More information about the openjfx-dev
mailing list