Skip to content

Commit 2d7c507

Browse files
committed
8305778: javax/swing/JTableHeader/6884066/bug6884066.java: Unexpected header's value; index = 4 value = E
Reviewed-by: serb, jdv
1 parent e1b06ea commit 2d7c507

File tree

1 file changed

+53
-35
lines changed

1 file changed

+53
-35
lines changed

test/jdk/javax/swing/JTableHeader/6884066/bug6884066.java

+53-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,56 +23,74 @@
2323

2424
/*
2525
@test
26-
@key headful
26+
@key headful
2727
@bug 6884066
2828
@summary JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
29-
@author Alexander Potochkin
3029
@run main bug6884066
3130
*/
3231

33-
import javax.swing.*;
32+
import java.awt.event.InputEvent;
33+
import java.awt.Point;
34+
import java.awt.Robot;
35+
import javax.swing.JFrame;
36+
import javax.swing.JTable;
3437
import javax.swing.table.JTableHeader;
3538
import javax.swing.table.TableColumnModel;
3639
import javax.swing.table.TableColumn;
37-
import java.awt.*;
38-
import java.awt.event.InputEvent;
40+
import javax.swing.SwingUtilities;
41+
import javax.swing.UIManager;
3942

4043
public class bug6884066 {
44+
private static JFrame frame;
4145
private static JTableHeader header;
46+
private static volatile Point point;
4247

4348
public static void main(String[] args) throws Exception {
49+
try {
50+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
4451

45-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
46-
47-
Robot robot = new Robot();
48-
robot.setAutoDelay(20);
49-
SwingUtilities.invokeAndWait(new Runnable() {
50-
public void run() {
51-
// just to quickly grab a column model
52-
JTable table = new JTable(10, 5);
53-
header = new JTableHeader(table.getColumnModel());
54-
checkColumn(0, "A");
55-
JFrame frame = new JFrame("standalone header");
56-
frame.add(header);
57-
frame.pack();
58-
frame.setVisible(true);
59-
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
52+
Robot robot = new Robot();
53+
robot.setAutoDelay(100);
54+
SwingUtilities.invokeAndWait(new Runnable() {
55+
public void run() {
56+
// just to quickly grab a column model
57+
JTable table = new JTable(10, 5);
58+
header = new JTableHeader(table.getColumnModel());
59+
checkColumn(0, "A");
60+
frame = new JFrame("standalone header");
61+
frame.add(header);
62+
frame.pack();
63+
frame.setLocationRelativeTo(null);
64+
frame.setVisible(true);
65+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
66+
}
67+
});
68+
robot.waitForIdle();
69+
robot.delay(1000);
70+
SwingUtilities.invokeAndWait(() -> {
71+
point = header.getLocationOnScreen();
72+
});
73+
robot.mouseMove(point.x + 3, point.y + 3);
74+
robot.waitForIdle();
75+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
76+
for (int i = 0; i < header.getWidth() - 3; i++) {
77+
robot.mouseMove(point.x + i, point.y + 3);
6078
}
61-
});
62-
robot.waitForIdle();
63-
Point point = header.getLocationOnScreen();
64-
robot.mouseMove(point.x + 3, point.y + 3);
65-
robot.mousePress(InputEvent.BUTTON1_MASK);
66-
for (int i = 0; i < header.getWidth() - 3; i++) {
67-
robot.mouseMove(point.x + i, point.y + 3);
79+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
80+
robot.waitForIdle();
81+
SwingUtilities.invokeAndWait(new Runnable() {
82+
public void run() {
83+
TableColumnModel model = header.getColumnModel();
84+
checkColumn(model.getColumnCount() - 1, "A");
85+
}
86+
});
87+
} finally {
88+
SwingUtilities.invokeAndWait(() -> {
89+
if (frame != null) {
90+
frame.dispose();
91+
}
92+
});
6893
}
69-
robot.mouseRelease(InputEvent.BUTTON1_MASK);
70-
SwingUtilities.invokeAndWait(new Runnable() {
71-
public void run() {
72-
TableColumnModel model = header.getColumnModel();
73-
checkColumn(model.getColumnCount() - 1, "A");
74-
}
75-
});
7694
}
7795

7896
private static void checkColumn(int index, String str) {

0 commit comments

Comments
 (0)