Path: blob/master/test/jdk/javax/accessibility/4715503/AccessibleJTableCellBoundingRectangleTest.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 471550327* @summary AccessibleTable cannot get the Bounding Rectangle of Table Header Cells.28* @run main AccessibleJTableCellBoundingRectangleTest29*/3031import java.awt.Rectangle;32import java.awt.Robot;3334import javax.swing.JFrame;35import javax.swing.JTable;36import javax.swing.SwingUtilities;3738public class AccessibleJTableCellBoundingRectangleTest {39private static JTable jTable;40private static JFrame jFrame;4142private static Object[][] rowData = { { "01", "02", "03", "04", "05" },43{ "11", "12", "13", "14", "15" }, { "21", "22", "23", "24", "25" },44{ "31", "32", "33", "34", "35" }, { "41", "42", "43", "44", "45" } };4546private static Object[] colNames = { "1", "2", "3", "4", "5" };4748private static void doTest() throws Exception {49try {50SwingUtilities.invokeAndWait(() -> createGUI());51Robot robot = new Robot();52robot.setAutoDelay(500);53robot.waitForIdle();5455for (int i = 0; i <= colNames.length - 1; i++) {56try {57Rectangle bounds =58jTable.getTableHeader().getAccessibleContext().getAccessibleChild(i)59.getAccessibleContext().getAccessibleComponent().getBounds();6061if (bounds != null) {62System.out.println("Column " + i + " Bounds: " + bounds);63} else {64throw new RuntimeException(65"Bounding Rectangles getting bounding rectangle for table header cells is null");66}67} catch (Exception e) {68throw new RuntimeException("Bounding Rectangles getting bounding rectangle for "69+ "table header cells threw an exception:\n" + e);70}71}72} finally {73SwingUtilities.invokeAndWait(() -> jFrame.dispose());74}75}7677private static void createGUI() {78jTable = new JTable(rowData, colNames);79jFrame = new JFrame();80jFrame.setBounds(100, 100, 300, 300);81jFrame.getContentPane().add(jTable);82jFrame.setVisible(true);83}8485public static void main(String args[]) throws Exception {86doTest();87System.out.println("Test Passed");88}89}90919293