Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6672644: JComboBox still scrolling if switch to another window and return back #20845

Closed
wants to merge 10 commits into from

Conversation

DamonGuy
Copy link
Contributor

@DamonGuy DamonGuy commented Sep 4, 2024

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.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-6672644: JComboBox still scrolling if switch to another window and return back (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20845/head:pull/20845
$ git checkout pull/20845

Update a local copy of the PR:
$ git checkout pull/20845
$ git pull https://git.openjdk.org/jdk.git pull/20845/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20845

View PR using the GUI difftool:
$ git pr show -t 20845

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20845.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 4, 2024

👋 Welcome back dnguyen! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 4, 2024

@DamonGuy This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

6672644: JComboBox still scrolling if switch to another window and return back

Reviewed-by: abhiscxk, psadhukhan

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 63 new commits pushed to the master branch:

  • 50c099d: 8344799: Remove permissions checks from java.awt.Desktop
  • e21d06f: 8344338: javax/swing/JTextArea/bug4265784.java fails on Ubuntu 24.04.1
  • db44e97: 8344798: Shenandoah: Use more descriptive variable names in shPhaseTimings.cpp
  • c199f53: 8344336: SM cleanup of java.lang.System, Runtime, String, StackWalker
  • 0f458e2: 8342903: Deprecate for removal java.awt.Window.getWarningString()
  • efeacfe: 8344646: The libjsig deprecation warning should go to stderr not stdout
  • 2214906: 8272339: Update notes section from serialver man page
  • cee74f9: 8338536: Permanently disable remote code downloading in JNDI
  • 7709d43: 8344782: Cleanup left over doPrivileged calls and imports in java.desktop
  • e03b150: 8178966: Don't swallow early bootstrap exceptions in Boolean.getBoolean, Integer.getInteger and Long.getLong
  • ... and 53 more: https://git.openjdk.org/jdk/compare/f525290000bf8583617047aaeb894bf90332d2e9...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 4, 2024
@openjdk
Copy link

openjdk bot commented Sep 4, 2024

@DamonGuy The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Sep 4, 2024
@mlbridge
Copy link

mlbridge bot commented Sep 4, 2024

@kumarabhi006
Copy link
Contributor

@DamonGuy are you able to reproduce the issue on linux machine? I tried on windows and linux, was able to reproduce it only on windows.
I checked on Ubuntu-22.04 and I can see the list is not scrolling and is stopped. Could you please confirm the same?

@kumarabhi006
Copy link
Contributor

I can verify on linux machine that it is suto-scrolling but it is intermittent on windows as well as on linux. Sometimes the list is scrolling and sometimes it's not. Are you facing the same?
To regain focus, if click on frame title bar then the intermittent issue can be observed.

@DamonGuy DamonGuy changed the title 6672644: JComboBox still scrolling if switch to another window and return back. 6672644: JComboBox still scrolling if switch to another window and return back Sep 5, 2024
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 3, 2024

@DamonGuy This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@DamonGuy DamonGuy marked this pull request as draft October 22, 2024 20:18
@openjdk openjdk bot removed the rfr Pull request is ready for review label Oct 22, 2024
@DamonGuy
Copy link
Contributor Author

DamonGuy commented Nov 5, 2024

@kumarabhi006 Tested with the additional changes I made. Looks like it's working now. No other tests are failing in CI with the changes either. Can you check it out again?

@DamonGuy DamonGuy marked this pull request as ready for review November 5, 2024 22:25
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 5, 2024
Comment on lines 1240 to 1244
if (incrButton.isFocusPainted()) {
incrButton.doClick();
} else if (decrButton.isFocusPainted()) {
decrButton.doClick();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this doClick block is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scrollbar increase and decrease buttons stay visually clicked down. Trying to change setFocusPainted or setSelected didn't seem to resolve this. However, adding a doClick resolves it and doesn't seem to interfere with the positioning of the scrolled item.

To be sure, I ran this on CI on all OS's and I didn't run into an issue. I'm open to other suggestions for fixing this visually, but this seemed like the cleanest way to do so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-11-12 at 9 46 35 AM

Here's an example of the fix WITHOUT the doClick on Metal L&F. The JComboBox menu isn't auto-scrolling but the down-arrow button still looks pressed.

Screenshot 2024-11-12 at 9 49 17 AM

And here's the same example but WITH the doClick. More as I'd expect from the behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we dont press on down-arrow button but press on the down viewport area, in which case doesn't it get reproduced?
Also doClick spec says

"Programmatically perform a "click". This does the same
     * thing as if the user had pressed and released the button.
     * The button stays visually "pressed" for <code>pressTime</code>
     *  milliseconds."

which does not seem to be right for this case..
What if you try to check button isPressed() and if so, do button setPress(false)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't think about that scenario. isPressed() definitely makes more sense then. I've updated it to that.

Tested it and seems to work just as well. Thanks for the suggestion.

Copy link
Contributor

@kumarabhi006 kumarabhi006 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me now. Tested in linux platform and it worked as expected.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 21, 2024
@DamonGuy
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 22, 2024

Going to push as commit 1114704.
Since your change was applied there have been 83 commits pushed to the master branch:

  • 98b6678: 8343741: SA jstack --mixed should print information about VM locks
  • 1b2d9ca: 8344881: Problemlist java/awt/Robot/InfiniteLoopException.java on Linux
  • 6aec2dc: 8344788: Specify that the access control context parameters of Subject.doAsPrivileged are ignored
  • 079f503: 8344568: Renaming ceil_log2 to log2i_ceil
  • 51763b6: 8344525: Fix leftover ExceptionOccurred in java.base
  • 4b16530: 8344795: Remove uses of AccessControlContext in java.desktop module
  • 5154b71: 8343598: Since Checker can mark some preview elements as new even if bytecode reference is identical
  • 8b98f95: 8298387: Implement JEP 497: Quantum-Resistant Module-Lattice-Based Digital Signature Algorithm
  • 21e0fb8: 8343529: serviceability/sa/ClhsdbWhere.java fails AssertionFailure: Corrupted constant pool
  • 13987b4: 8298390: Implement JEP 496: Quantum-Resistant Module-Lattice-Based Key Encapsulation Mechanism
  • ... and 73 more: https://git.openjdk.org/jdk/compare/f525290000bf8583617047aaeb894bf90332d2e9...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 22, 2024
@openjdk openjdk bot closed this Nov 22, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 22, 2024
@openjdk
Copy link

openjdk bot commented Nov 22, 2024

@DamonGuy Pushed as commit 1114704.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants