Skip to content

6318027: BasicScrollBarUI does not disable timer when enclosing frame is disabled. #20346

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

Closed
wants to merge 12 commits into from

Conversation

prsadhuk
Copy link
Contributor

@prsadhuk prsadhuk commented Jul 26, 2024

Issue is
BasicScrollBarUI.ArrowButtonListener starts a timer in mousePressed(), and stops it in mouseReleased(). If the frame containing the scrollbar is disabled between the MOUSE_PRESSED and the MOUSE_RELEASED events, the mouseReleased() method is never called. If the frame is then re-enabled, the still-running timer causes it to scroll all the way to the end.
Fix is to check if ArrowButtonListener.handledEvent is still set when ActionEvent is processed then stop the timer and reset this variable.

CI testing is green and also SwingSet2 JScrollPane scrolling with this modification..


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

Warning

 ⚠️ Found trailing period in issue title for 6318027: BasicScrollBarUI does not disable timer when enclosing frame is disabled.

Issue

  • JDK-6318027: BasicScrollBarUI does not disable timer when enclosing frame is disabled. (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20346

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 26, 2024

👋 Welcome back psadhukhan! 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 Jul 26, 2024

@prsadhuk 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:

6318027: BasicScrollBarUI does not disable timer when enclosing frame is disabled.

Reviewed-by: abhiscxk, tr

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 360 new commits pushed to the master branch:

  • 88ccbb6: 8336934: Clean up JavaLangReflectAccess
  • d728107: 8338482: com/sun/jdi/ThreadMemoryLeakTest.java requires that compressed oops are enabled
  • 1ebf2cf: 8336756: Improve ClassFile Annotation writing
  • 0267284: 8338611: java.lang.module specification wording not aligned with JEP 261
  • c646efc: 8205957: setfldw001/TestDescription.java fails with bad field value
  • 285ceb9: 8336529: (fs) UnixFileAttributeViews setTimes() failing on armhf, Ubuntu noble
  • 55a97ec: 8336729: C2: Div/Mod nodes without zero check could be split through iv phi of outer loop of long counted loop nest resulting in SIGFPE
  • b442003: 8338623: StackCounter adding extraneous slots for receiver invoke instructions
  • bc2700b: 8282944: GHA: Add Alpine Linux x86_64 pre-integration check
  • 686eb23: 8336817: Several methods on DatagramSocket and MulticastSocket do not specify behaviour when already closed or connected
  • ... and 350 more: https://git.openjdk.org/jdk/compare/871362870ea8dc5f4ac186876e91023116891a5b...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
Copy link

openjdk bot commented Jul 26, 2024

@prsadhuk 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 Jul 26, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 26, 2024
@mlbridge
Copy link

mlbridge bot commented Jul 26, 2024

Comment on lines 77 to 87
frame = new JFrame(DisableFrameFromScrollBar.class.getName());
bar = new JScrollBar();
bar.getModel().addChangeListener(new DisableChangeListener(frame));
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(bar);

frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(150, 150);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be pushed to a helper method.

// Stop the timer if handledEvent is still set indicating
// mouseReleased is not called after mousePressed when
// this AcionEvent is being processed
if (buttonListener.handledEvent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the fix is added in BasicScrollBarUI, will it affect Aqua ScrollBar also?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think most L&F's ScrollBarUI classes are extending BasicScrollBarUI so it might be worth checking if this issue also occurs in those L&Fs too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aqua ScrollBar does not have arrowbutton so ArrowButtonListener, as mentioned in JBS, is not there but there is trackpad and there is similar issue with it but it cannot be handled with this "handledEvent" and needs to be handled separately so as of now AquaL&F is omitted from the testing..Other L&F are fine as per the testing..

Comment on lines 80 to 81
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(bar);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess getContentPane may be removed.


frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(150, 150);
Copy link
Contributor

Choose a reason for hiding this comment

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

setting frame size explicitly after calling frame.pack() looks redundant.

public void run() {
Point p = bar.getLocationOnScreen();
Rectangle rect = bar.getBounds();
result[0] = new Point((int) (p.x + rect.width/2),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
result[0] = new Point((int) (p.x + rect.width/2),
result[0] = new Point((int) (p.x + rect.width / 2),


public static class DisableChangeListener implements ChangeListener {
private final JFrame m_frame;
private boolean m_done = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

default value for a boolean is false, no need to set it explicitly.

}

public void stateChanged(ChangeEvent p_e) {
if (! m_done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (! m_done) {
if (!m_done) {

@kumarabhi006
Copy link
Contributor

@prsadhuk I was verifying the test and for Aqua L&F looks like the timer is not stopped and scrollbar scrolls down to the end and it doesn't throw any exception also.
Test ran fine for Metal, Nimbus and Motif L&Fs.

@@ -527,6 +527,12 @@ void setScrollByBlock(final boolean block) {
}

public void actionPerformed(final ActionEvent e) {
if (fTrackHighlight != Hit.NONE && !fTrackListener.fStillInTrack) {
Copy link
Contributor

Choose a reason for hiding this comment

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

fTrackListener.fStillInTrack value is true and here the condition is to check for negation which makes it to false and overall condition evaluates to false and that may be the reason that the timer is not stopped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes thats the drawback of indirect checking....I have modified PR to check for frame disable directly and stop the timer..

Thread.sleep(200);
} while(isAdjusting && !doCheck);
if (bar.getValue() == (bar.getMaximum() - bar.getVisibleAmount())) {
throw new RuntimeException("ScrollBar did't disable timer");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new RuntimeException("ScrollBar did't disable timer");
throw new RuntimeException("ScrollBar didn't disable timer");


private static JFrame frame;
private static JScrollBar bar;
private static Robot robot;
Copy link
Contributor

Choose a reason for hiding this comment

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

robot can be local variable.

@mrserb
Copy link
Member

mrserb commented Aug 16, 2024

BasicScrollBarUI.ArrowButtonListener starts a timer in mousePressed(), and stops it in mouseReleased(). If the frame containing the scrollbar is disabled between the MOUSE_PRESSED and the MOUSE_RELEASED events, the mouseReleased() method is never called. If

What happens if you make the scrollbar invisible in this case?

do {
if (parent instanceof javax.swing.JFrame par) {
if (!par.isEnabled()) {
((Timer)e.getSource()).stop();
Copy link
Member

Choose a reason for hiding this comment

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

Is the "TImer" always the source for the event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the method employs same way to stop the timer in other cases too..
Also, if the scrollbar is made invisible and then visible instead of frame, it doesn't scroll to the end and behaves as expected..

do {
if (parent instanceof javax.swing.JFrame par) {
if (!par.isEnabled()) {
((Timer)e.getSource()).stop();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
((Timer)e.getSource()).stop();
((Timer) e.getSource()).stop();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same spacing issue in other places too as mentioned above...

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok... as you are changing the file I guess you can expand the wild imports, It's up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

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.

minor sorting of imports.

Comment on lines 32 to 35
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Insets;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Insets;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;

Comment on lines 59 to 61
import apple.laf.JRSUIConstants.Hit;
import apple.laf.JRSUIConstants.Orientation;
import apple.laf.JRSUIConstants.NothingToScroll;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import apple.laf.JRSUIConstants.Hit;
import apple.laf.JRSUIConstants.Orientation;
import apple.laf.JRSUIConstants.NothingToScroll;
import apple.laf.JRSUIConstants.Hit;
import apple.laf.JRSUIConstants.NothingToScroll;
import apple.laf.JRSUIConstants.Orientation;

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.

Ran the test and verified the latest fix on different platforms (mac, windows and linux). It works as expected and looks good to me now.

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

@TejeshR13 TejeshR13 left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@prsadhuk
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Aug 21, 2024

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

  • 88ccbb6: 8336934: Clean up JavaLangReflectAccess
  • d728107: 8338482: com/sun/jdi/ThreadMemoryLeakTest.java requires that compressed oops are enabled
  • 1ebf2cf: 8336756: Improve ClassFile Annotation writing
  • 0267284: 8338611: java.lang.module specification wording not aligned with JEP 261
  • c646efc: 8205957: setfldw001/TestDescription.java fails with bad field value
  • 285ceb9: 8336529: (fs) UnixFileAttributeViews setTimes() failing on armhf, Ubuntu noble
  • 55a97ec: 8336729: C2: Div/Mod nodes without zero check could be split through iv phi of outer loop of long counted loop nest resulting in SIGFPE
  • b442003: 8338623: StackCounter adding extraneous slots for receiver invoke instructions
  • bc2700b: 8282944: GHA: Add Alpine Linux x86_64 pre-integration check
  • 686eb23: 8336817: Several methods on DatagramSocket and MulticastSocket do not specify behaviour when already closed or connected
  • ... and 350 more: https://git.openjdk.org/jdk/compare/871362870ea8dc5f4ac186876e91023116891a5b...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Aug 21, 2024

@prsadhuk Pushed as commit cafb3dc.

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

@prsadhuk prsadhuk deleted the JDK-6318027 branch August 21, 2024 07:12
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