Path: blob/master/test/jdk/javax/accessibility/8283015/AccessibleJTableCellNameTest.java
66644 views
/*1* Copyright (c) 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 471549627* @summary AccessibleJTableCell.getAccessible name incorrectly returns28* cell instance string instead of cell text.29* @run main AccessibleJTableCellNameTest30*/3132import java.awt.Robot;3334import javax.accessibility.Accessible;35import javax.swing.JFrame;36import javax.swing.JTable;37import javax.swing.SwingUtilities;3839public class AccessibleJTableCellNameTest {40private static JTable jTable;41private static JFrame jFrame;42private static volatile Accessible accessible;4344private static Object[][] rowData = {45{ "01", "02", "03", "04", "05" },46{ "11", "12", "13", "14", "15" },47{ "21", "22", "23", "24", "25" },48{ "31", "32", "33", "34", "35" },49{ "41", "42", "43", "44", "45" } };5051private static Object[] colNames = { "1", "2", "3", "4", "5" };5253private static void doTest() throws Exception {54try {55SwingUtilities.invokeAndWait(() -> createGUI());56Robot robot = new Robot();57robot.setAutoDelay(500);58robot.waitForIdle();5960SwingUtilities.invokeAndWait(() -> {61for (int i = 0; i <= colNames.length - 1; i++) {62Accessible accessible = jTable.getAccessibleContext().getAccessibleTable()63.getAccessibleColumnHeader().getAccessibleAt(0, i);6465if (!(accessible.getAccessibleContext().getAccessibleName().equals(colNames[i]))) {66throw new RuntimeException(67"AccessibleJTableCell.getAccessibleName returns correct name for header cells");68}69}70});71} finally {72SwingUtilities.invokeAndWait(() -> jFrame.dispose());73}74}7576private static void createGUI() {77jTable = new JTable(rowData, colNames);78jFrame = new JFrame();79jFrame.setBounds(100, 100, 300, 300);80jFrame.getContentPane().add(jTable);81jFrame.setVisible(true);82}8384public static void main(String args[]) throws Exception {85doTest();86System.out.println("Test Passed");87}88}89909192