Skip to content

Commit

Permalink
8299713: Test javax/swing/JTableHeader/6889007/bug6889007.java failed…
Browse files Browse the repository at this point in the history
…: Wrong type of cursor

Reviewed-by: serb, tr
  • Loading branch information
prsadhuk committed May 1, 2023
1 parent b3dbf28 commit b54c4a3
Showing 1 changed file with 59 additions and 24 deletions.
83 changes: 59 additions & 24 deletions test/jdk/javax/swing/JTableHeader/6889007/bug6889007.java
Expand Up @@ -23,28 +23,42 @@

/*
@test
@key headful
@key headful
@bug 6889007
@summary No resize cursor during hovering mouse over JTable
@author Alexander Potochkin
*/

import javax.swing.*;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.plaf.basic.BasicTableHeaderUI;
import javax.swing.table.JTableHeader;
import java.awt.*;
import javax.swing.JTable;
import javax.swing.SwingUtilities;

public class bug6889007 {

static JFrame frame;
static Robot robot;
static volatile Point point;
static volatile int width;
static volatile int height;

public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(20);
try {
robot = new Robot();
robot.setAutoDelay(100);

final JFrame frame = new JFrame();
frame.setUndecorated(true);
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame();
frame.setUndecorated(true);

SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JTableHeader th = new JTableHeader();
Expand All @@ -56,21 +70,33 @@ public void run() {
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
robot.waitForIdle();
robot.delay(1000);
SwingUtilities.invokeAndWait(() -> {
point = frame.getLocationOnScreen();
width = frame.getWidth();
height = frame.getHeight();
});
int shift = 10;
int x = point.x;
int y = point.y + height/2;
for(int i = -shift; i < width + 2*shift; i++) {
robot.mouseMove(x++, y);
robot.waitForIdle();
}
});
robot.waitForIdle();
Point point = frame.getLocationOnScreen();
int shift = 10;
int x = point.x;
int y = point.y + frame.getHeight()/2;
for(int i = -shift; i < frame.getWidth() + 2*shift; i++) {
robot.mouseMove(x++, y);
}
robot.waitForIdle();
// 9 is a magic test number
if (MyTableHeaderUI.getTestValue() != 9) {
throw new RuntimeException("Unexpected test number "
+ MyTableHeaderUI.getTestValue());
robot.waitForIdle();
// 9 is a magic test number
if (MyTableHeaderUI.getTestValue() != 9) {
throw new RuntimeException("Unexpected test number "
+ MyTableHeaderUI.getTestValue());
}
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
System.out.println("ok");
}
Expand All @@ -83,6 +109,15 @@ protected void rolloverColumnUpdated(int oldColumn, int newColumn) {
Cursor cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
if (oldColumn != -1 && newColumn != -1 &&
header.getCursor() != cursor) {
try {
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screen = new Rectangle(0, 0,
(int) screenSize.getWidth(),
(int) screenSize.getHeight());
BufferedImage img = robot.createScreenCapture(screen);
ImageIO.write(img, "png", new java.io.File("image.png"));
} catch (Exception e) {}
throw new RuntimeException("Wrong type of cursor!");
}
}
Expand Down

3 comments on commit b54c4a3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on b54c4a3 Jul 5, 2023

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 b54c4a3 Jul 5, 2023

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-b54c4a33 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 b54c4a33 from the openjdk/jdk repository.

The commit being backported was authored by Prasanta Sadhukhan on 1 May 2023 and was reviewed by Sergey Bylokhov and Tejesh R.

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 GoeLin-backport-b54c4a33:GoeLin-backport-b54c4a33
$ git checkout GoeLin-backport-b54c4a33
# 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 GoeLin-backport-b54c4a33

Please sign in to comment.