Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTable/7188612/JTableAccessibleGetLocationOnScreen.java
38853 views
/*1* Copyright (c) 2012, 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* Portions Copyright (c) 2012 IBM Corporation25*/2627/* @test28* @bug 718861229* @summary AccessibleTableHeader and AccessibleJTableCell should stick to30* AccessibleComponent.getLocationOnScreen api.31* @author Frank Ding32*/3334import javax.accessibility.AccessibleComponent;35import javax.accessibility.AccessibleTable;36import javax.swing.JComponent;37import javax.swing.JFrame;38import javax.swing.JTable;39import javax.swing.SwingUtilities;4041public class JTableAccessibleGetLocationOnScreen {42private static JFrame frame;43private static JTable table;4445public static void main(String[] args) throws Exception {4647SwingUtilities.invokeAndWait(new Runnable() {4849@Override50public void run() {51constructInEDT();52try {53assertGetLocation();54} finally {55frame.dispose();56}57}58});5960}6162private static void constructInEDT() {63String[] columnNames = { "col1", "col2", };64Object[][] data = { { "row1, col1", "row1, col2" },65{ "row2, col1", "row2, col2" }, };6667frame = new JFrame(68"JTable AccessibleTableHeader and AccessibleJTableCell test");69frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);70table = new JTable(data, columnNames);71frame.add(table);72frame.pack();73}7475private static void assertGetLocation() {76// the frame is now invisible77// test getLocationOnScreen() of78// JTable$AccessibleJTable$AccessibleJTableHeaderCell79// and JTable$AccessibleJTable$AccessibleJTableCell80AccessibleTable accessibleTable = (AccessibleTable) table81.getAccessibleContext();82AccessibleTable header = accessibleTable.getAccessibleColumnHeader();83AccessibleComponent accessibleComp1 = (AccessibleComponent) header84.getAccessibleAt(0, 0);85// getLocation() must be null according to its javadoc and no exception86// is thrown87if (null != accessibleComp1.getLocationOnScreen()) {88throw new RuntimeException(89"JTable$AccessibleJTable$AccessibleJTableHeaderCell."90+ "getLocation() must be null");91}9293JComponent.AccessibleJComponent accessibleJComponent =94(JComponent.AccessibleJComponent) table.getAccessibleContext();95AccessibleComponent accessibleComp2 = (AccessibleComponent)96accessibleJComponent.getAccessibleChild(3);97// getLocation() must be null according to its javadoc and no exception98// is thrown99if (null != accessibleComp2.getLocationOnScreen()) {100throw new RuntimeException("JTable$AccessibleJTable$"101+ "AccessibleJTableCell.getLocation() must be null");102}103104}105}106107108