Skip to content

Commit c20cb0a

Browse files
committed
8282933: Create a test for JDK-4529616
Backport-of: a0b984a778c1f9a89fd3e1e474b5a5165a0841b0
1 parent 676d7d6 commit c20cb0a

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2002, 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 4529616
28+
* @summary AccessibleJTableCell.isShowing() returns false
29+
* when the cell is actually on the screen.
30+
* @run main AccessibleJTableCellTest
31+
*/
32+
33+
import java.awt.Robot;
34+
import java.util.concurrent.atomic.AtomicBoolean;
35+
36+
import javax.swing.JFrame;
37+
import javax.swing.JTable;
38+
import javax.swing.SwingUtilities;
39+
40+
public class AccessibleJTableCellTest {
41+
private static JTable jTable;
42+
private static JFrame jFrame;
43+
44+
private static Object[][] rowData = { { "01", "02", "03", "04", "05" },
45+
{ "11", "12", "13", "14", "15" }, { "21", "22", "23", "24", "25" },
46+
{ "31", "32", "33", "34", "35" }, { "41", "42", "43", "44", "45" } };
47+
48+
private static Object[] colNames = { "1", "2", "3", "4", "5" };
49+
50+
private static void doTest() throws Exception {
51+
try {
52+
SwingUtilities.invokeAndWait(() -> createGUI());
53+
54+
Robot robot = new Robot();
55+
robot.setAutoDelay(500);
56+
robot.waitForIdle();
57+
58+
for (int i = 0; i <= colNames.length - 1; i++) {
59+
if (!isJTableCellShowing(i)) {
60+
throw new RuntimeException(
61+
"Assertion Failed: JTable accessible child " + i
62+
+ " isShowing returns false");
63+
}
64+
}
65+
} finally {
66+
SwingUtilities.invokeAndWait(() -> jFrame.dispose());
67+
}
68+
}
69+
70+
private static boolean isJTableCellShowing(int i) throws Exception {
71+
AtomicBoolean isShowing = new AtomicBoolean();
72+
SwingUtilities.invokeAndWait(() -> isShowing
73+
.set(jTable.getAccessibleContext().getAccessibleChild(i)
74+
.getAccessibleContext().getAccessibleComponent().isShowing()));
75+
76+
return isShowing.get();
77+
}
78+
79+
private static void createGUI() {
80+
jTable = new JTable(rowData, colNames);
81+
jFrame = new JFrame();
82+
jFrame.setBounds(100, 100, 300, 300);
83+
jFrame.getContentPane().add(jTable);
84+
jFrame.setLocationRelativeTo(null);
85+
jFrame.setVisible(true);
86+
}
87+
88+
public static void main(String args[]) throws Exception {
89+
doTest();
90+
System.out.println("Test Passed");
91+
}
92+
}

0 commit comments

Comments
 (0)