Path: blob/master/test/jdk/javax/accessibility/4529616/AccessibleJTableCellTest.java
66644 views
/*1* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 452961627* @summary AccessibleJTableCell.isShowing() returns false28* when the cell is actually on the screen.29* @run main AccessibleJTableCellTest30*/3132import java.awt.Robot;33import java.util.concurrent.atomic.AtomicBoolean;3435import javax.swing.JFrame;36import javax.swing.JTable;37import javax.swing.SwingUtilities;3839public class AccessibleJTableCellTest {40private static JTable jTable;41private static JFrame jFrame;4243private 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" } };4647private static Object[] colNames = { "1", "2", "3", "4", "5" };4849private static void doTest() throws Exception {50try {51SwingUtilities.invokeAndWait(() -> createGUI());5253Robot robot = new Robot();54robot.setAutoDelay(500);55robot.waitForIdle();5657for (int i = 0; i <= colNames.length - 1; i++) {58if (!isJTableCellShowing(i)) {59throw new RuntimeException(60"Assertion Failed: JTable accessible child " + i61+ " isShowing returns false");62}63}64} finally {65SwingUtilities.invokeAndWait(() -> jFrame.dispose());66}67}6869private static boolean isJTableCellShowing(int i) throws Exception {70AtomicBoolean isShowing = new AtomicBoolean();71SwingUtilities.invokeAndWait(() -> isShowing72.set(jTable.getAccessibleContext().getAccessibleChild(i)73.getAccessibleContext().getAccessibleComponent().isShowing()));7475return isShowing.get();76}7778private static void createGUI() {79jTable = new JTable(rowData, colNames);80jFrame = new JFrame();81jFrame.setBounds(100, 100, 300, 300);82jFrame.getContentPane().add(jTable);83jFrame.setLocationRelativeTo(null);84jFrame.setVisible(true);85}8687public static void main(String args[]) throws Exception {88doTest();89System.out.println("Test Passed");90}91}929394