Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/javax/accessibility/4715503/AccessibleJTableCellBoundingRectangleTest.java
66644 views
1
/*
2
* Copyright (c) 2022, 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
* @key headful
27
* @bug 4715503
28
* @summary AccessibleTable cannot get the Bounding Rectangle of Table Header Cells.
29
* @run main AccessibleJTableCellBoundingRectangleTest
30
*/
31
32
import java.awt.Rectangle;
33
import java.awt.Robot;
34
35
import javax.swing.JFrame;
36
import javax.swing.JTable;
37
import javax.swing.SwingUtilities;
38
39
public class AccessibleJTableCellBoundingRectangleTest {
40
private static JTable jTable;
41
private static JFrame jFrame;
42
43
private static Object[][] rowData = { { "01", "02", "03", "04", "05" },
44
{ "11", "12", "13", "14", "15" }, { "21", "22", "23", "24", "25" },
45
{ "31", "32", "33", "34", "35" }, { "41", "42", "43", "44", "45" } };
46
47
private static Object[] colNames = { "1", "2", "3", "4", "5" };
48
49
private static void doTest() throws Exception {
50
try {
51
SwingUtilities.invokeAndWait(() -> createGUI());
52
Robot robot = new Robot();
53
robot.setAutoDelay(500);
54
robot.waitForIdle();
55
56
for (int i = 0; i <= colNames.length - 1; i++) {
57
try {
58
Rectangle bounds =
59
jTable.getTableHeader().getAccessibleContext().getAccessibleChild(i)
60
.getAccessibleContext().getAccessibleComponent().getBounds();
61
62
if (bounds != null) {
63
System.out.println("Column " + i + " Bounds: " + bounds);
64
} else {
65
throw new RuntimeException(
66
"Bounding Rectangles getting bounding rectangle for table header cells is null");
67
}
68
} catch (Exception e) {
69
throw new RuntimeException("Bounding Rectangles getting bounding rectangle for "
70
+ "table header cells threw an exception:\n" + e);
71
}
72
}
73
} finally {
74
SwingUtilities.invokeAndWait(() -> jFrame.dispose());
75
}
76
}
77
78
private static void createGUI() {
79
jTable = new JTable(rowData, colNames);
80
jFrame = new JFrame();
81
jFrame.setBounds(100, 100, 300, 300);
82
jFrame.getContentPane().add(jTable);
83
jFrame.setVisible(true);
84
}
85
86
public static void main(String args[]) throws Exception {
87
doTest();
88
System.out.println("Test Passed");
89
}
90
}
91
92
93