Skip to content

Commit

Permalink
8318154: Improve stability of WheelModifier.java test
Browse files Browse the repository at this point in the history
Reviewed-by: aivanov
  • Loading branch information
Renjithkannath authored and aivanov-jdk committed Oct 16, 2023
1 parent a36eaf0 commit 668d4b0
Showing 1 changed file with 24 additions and 9 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,14 +26,23 @@
@key headful
@bug 8041470
@summary JButtons stay pressed after they have lost focus if you use the mouse wheel
@author Anton Nashatyrev
*/

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.AWTEvent;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.concurrent.CountDownLatch;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class WheelModifier {

JFrame f;
Expand All @@ -44,6 +53,9 @@ public class WheelModifier {
CountDownLatch releaseSema = new CountDownLatch(1);
volatile CountDownLatch wheelSema;

private volatile Point sLoc;
private volatile Dimension bSize;

void createGui() {
f = new JFrame("frame");
fb = new JButton("frame_button");
Expand Down Expand Up @@ -98,10 +110,13 @@ void run() throws Exception {
r.waitForIdle();
System.out.println("# Started");

Point sLoc = fb.getLocationOnScreen();
Dimension bSize = fb.getSize();
SwingUtilities.invokeAndWait(() -> {
sLoc = fb.getLocationOnScreen();
bSize = fb.getSize();
});

r.mouseMove(sLoc.x + bSize.width / 2, sLoc.y + bSize.height / 2);
r.mousePress(MouseEvent.BUTTON1_MASK);
r.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
pressSema.await();
System.out.println("# Pressed");

Expand All @@ -119,7 +134,7 @@ void run() throws Exception {
wheelSema.await();
System.out.println("# Wheeled 2");

r.mouseRelease(MouseEvent.BUTTON1_MASK);
r.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
releaseSema.await();
System.out.println("# Released!");
}
Expand Down

7 comments on commit 668d4b0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@SoniaZaldana
Copy link
Member

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 668d4b0 Jan 9, 2024

Choose a reason for hiding this comment

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

@SoniaZaldana the backport was successfully created on the branch backport-SoniaZaldana-668d4b07 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 668d4b07 from the openjdk/jdk repository.

The commit being backported was authored by Renjith Kannath Pariyangad on 16 Oct 2023 and was reviewed by Alexey Ivanov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-SoniaZaldana-668d4b07:backport-SoniaZaldana-668d4b07
$ git checkout backport-SoniaZaldana-668d4b07
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-SoniaZaldana-668d4b07

@luchenlin
Copy link

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 668d4b0 Jan 16, 2024

Choose a reason for hiding this comment

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

@luchenlin the backport was successfully created on the branch backport-luchenlin-668d4b07 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 668d4b07 from the openjdk/jdk repository.

The commit being backported was authored by Renjith Kannath Pariyangad on 16 Oct 2023 and was reviewed by Alexey Ivanov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-luchenlin-668d4b07:backport-luchenlin-668d4b07
$ git checkout backport-luchenlin-668d4b07
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-luchenlin-668d4b07

@luchenlin
Copy link

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 668d4b0 Jan 16, 2024

Choose a reason for hiding this comment

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

@luchenlin the backport was successfully created on the branch backport-luchenlin-668d4b07 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 668d4b07 from the openjdk/jdk repository.

The commit being backported was authored by Renjith Kannath Pariyangad on 16 Oct 2023 and was reviewed by Alexey Ivanov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev.git backport-luchenlin-668d4b07:backport-luchenlin-668d4b07
$ git checkout backport-luchenlin-668d4b07
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev.git backport-luchenlin-668d4b07

Please sign in to comment.