Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTable/4220171/bug4220171.java
38854 views
1
/*
2
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 4220171
27
* @author Konstantin Eremin
28
* @summary Tests
29
* @library ../../regtesthelpers
30
* @build Util
31
* @run main bug4220171
32
*/
33
import java.awt.Color;
34
import java.awt.Point;
35
import java.awt.Rectangle;
36
import java.awt.Robot;
37
import java.awt.event.InputEvent;
38
import java.awt.event.KeyEvent;
39
import javax.swing.*;
40
import javax.swing.border.LineBorder;
41
42
public class bug4220171 {
43
44
private static JTable table;
45
46
public static void main(String args[]) throws Exception {
47
48
Robot robot = new Robot();
49
robot.setAutoDelay(50);
50
51
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
52
53
public void run() {
54
createAndShowGUI();
55
}
56
});
57
58
robot.waitForIdle();
59
60
clickMouse(robot, 0, 0);
61
Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_ENTER);
62
robot.waitForIdle();
63
checkCell(0, 0);
64
65
clickMouse(robot, 0, 1);
66
Util.hitKeys(robot, KeyEvent.VK_D, KeyEvent.VK_E, KeyEvent.VK_ENTER);
67
robot.waitForIdle();
68
checkCell(0, 1);
69
70
clickMouse(robot, 1, 0);
71
Util.hitKeys(robot, KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_ENTER);
72
robot.waitForIdle();
73
checkCell(1, 0);
74
75
clickMouse(robot, 1, 1);
76
Util.hitKeys(robot, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_ENTER);
77
robot.waitForIdle();
78
checkCell(1, 1);
79
}
80
81
static void checkCell(final int row, final int column) throws Exception {
82
SwingUtilities.invokeAndWait(new Runnable() {
83
84
public void run() {
85
if (table.getValueAt(row, column) != null) {
86
throw new RuntimeException(
87
String.format("Cell (%d, %d) is editable", row, column));
88
}
89
}
90
});
91
}
92
93
static void clickMouse(Robot robot, int row, int column) throws Exception {
94
Point point = getCellClickPoint(row, column);
95
robot.mouseMove(point.x, point.y);
96
robot.mousePress(InputEvent.BUTTON1_MASK);
97
robot.mouseRelease(InputEvent.BUTTON1_MASK);
98
}
99
100
private static Point getCellClickPoint(final int row, final int column) throws Exception {
101
final Point[] result = new Point[1];
102
SwingUtilities.invokeAndWait(new Runnable() {
103
104
@Override
105
public void run() {
106
Rectangle rect = table.getCellRect(row, column, false);
107
Point point = new Point(rect.x + rect.width / 2,
108
rect.y + rect.height / 2);
109
SwingUtilities.convertPointToScreen(point, table);
110
result[0] = point;
111
}
112
});
113
114
return result[0];
115
}
116
117
private static void createAndShowGUI() {
118
JFrame frame = new JFrame("Test");
119
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
120
frame.setSize(200, 200);
121
122
table = new JTable(2, 2);
123
table.setEnabled(false);
124
125
frame.getContentPane().add(table);
126
frame.setVisible(true);
127
}
128
}
129
130