On Wed, 20 Nov 2024 07:20:05 GMT, Damon Nguyen <[email protected]> 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.
>
> Damon Nguyen has updated the pull request incrementally with one additional
> commit since the last revision:
>
> isPressed check and set
src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java
line 1224:
> 1222: * A listener to listen for keyboard focus changes.
> 1223: */
> 1224: protected class KeyboardFocusListener extends MouseAdapter
> implements PropertyChangeListener {
Why do you extends "MouseAdapter" ?
Is it really needed ?
test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java line 56:
> 54: .title("JComboBoxScrollFocusTest Test Instructions")
> 55: .instructions(INSTRUCTIONS)
> 56: .rows((int) INSTRUCTIONS.lines().count() + 2)
not required anymore.
test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java line 65:
> 63: private static JFrame createAndShowGUI() {
> 64: JFrame frame = new JFrame("JComboBoxScrollFocusTest Test Frame");
> 65: JComboBox combobox = new JComboBox();
Suggestion:
JComboBox<String> combobox = new JComboBox<>();
test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java line 66:
> 64: JFrame frame = new JFrame("JComboBoxScrollFocusTest Test Frame");
> 65: JComboBox combobox = new JComboBox();
> 66: for (int i = 0; i < 100; i ++) {
Suggestion:
for (int i = 0; i < 100; i++) {
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20845#discussion_r1851869858
PR Review Comment: https://git.openjdk.org/jdk/pull/20845#discussion_r1851871991
PR Review Comment: https://git.openjdk.org/jdk/pull/20845#discussion_r1851881030
PR Review Comment: https://git.openjdk.org/jdk/pull/20845#discussion_r1851881797