RFR: 6672644: JComboBox still scrolling if switch to another window and return back.
Harshitha Onkar
honkar at openjdk.org
Thu Sep 5 00:00:53 UTC 2024
On Wed, 4 Sep 2024 00:54:16 GMT, Damon Nguyen <dnguyen at openjdk.org> wrote:
> In a JComboBox, if the user opens the dropdown list and clicks and holds the down-button, then ALT-TABs to switch focus, when the user re-focuses the frame with the JComboBox and opens the dropdown list again, the list will still be scrolling even though the down-button isn't pressed.
>
> This isn't OS or L&F specific, although Aqua L&F does not have any directional arrows in the dropdown list (and is thus exempt). This led me to believe it could be handled in BasicComboBoxUI where focusLost and focusGain are used or isPopupVisible but the scroll behavior cannot be altered here. Likewise for BasicComboPopup where `autoscroll` is used. However, this behavior isn't related to autoscroll and is actually found in the JScrollbar of the JScrollpane inside of the JComboBox. The timer for the scroll action starts but is never stopped if focus is lost, so a new listener is created and used. The proposed solution uses `KeyboardFocusManager` to track the focus owner. The listener stops the `scrollTimer` when the `focusOwner` property is changed. With this change, the list no longer automatically scrolls when re-focused and instead opens normally.
>
> The included test is manual due to the need to confirm that the list still scrolls after ALT-TABing. The L&F is set to Metal since it is the cross-platform lookandfeel and has directional buttons for the JScrollPane list.
src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java line 1238:
> 1236: // Stop scrolling if no longer focus owner
> 1237: if (e.getNewValue() == null && scrollTimer.isRunning()) {
> 1238: scrollTimer.stop();
In some places `scrollTimer.stop()` is followed by `scrollbar.setValueIsAdjusting(false)`. Is this applicable for KeyboardFocusListener ?
For instance:
https://github.com/openjdk/jdk/blob/0cc3caf2b49426bb6738a9792c88275c0cc7774a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java#L1608
test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java line 59:
> 57: UnsupportedLookAndFeelException, ClassNotFoundException,
> 58: InstantiationException, IllegalAccessException, AWTException,
> 59: InterruptedException, InvocationTargetException {
Can this be simplified to throw generic Exception?
test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java line 85:
> 83: return frame;
> 84: }
> 85: }
EOF newline missing here
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20845#discussion_r1744633549
PR Review Comment: https://git.openjdk.org/jdk/pull/20845#discussion_r1744612747
PR Review Comment: https://git.openjdk.org/jdk/pull/20845#discussion_r1744613060
More information about the client-libs-dev
mailing list