Path: blob/master/test/jdk/javax/swing/JTable/7188612/JTableAccessibleGetLocationOnScreen.java
41155 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/*28* @test29* @key headful30* @bug 718861231* @summary AccessibleTableHeader and AccessibleJTableCell should stick to32* AccessibleComponent.getLocationOnScreen api.33* @author Frank Ding34*/3536import javax.accessibility.AccessibleComponent;37import javax.accessibility.AccessibleTable;38import javax.swing.JComponent;39import javax.swing.JFrame;40import javax.swing.JTable;41import javax.swing.SwingUtilities;4243public class JTableAccessibleGetLocationOnScreen {44private static JFrame frame;45private static JTable table;4647public static void main(String[] args) throws Exception {4849SwingUtilities.invokeAndWait(new Runnable() {5051@Override52public void run() {53constructInEDT();54try {55assertGetLocation();56} finally {57frame.dispose();58}59}60});6162}6364private static void constructInEDT() {65String[] columnNames = { "col1", "col2", };66Object[][] data = { { "row1, col1", "row1, col2" },67{ "row2, col1", "row2, col2" }, };6869frame = new JFrame(70"JTable AccessibleTableHeader and AccessibleJTableCell test");71frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);72table = new JTable(data, columnNames);73frame.add(table);74frame.pack();75}7677private static void assertGetLocation() {78// the frame is now invisible79// test getLocationOnScreen() of80// JTable$AccessibleJTable$AccessibleJTableHeaderCell81// and JTable$AccessibleJTable$AccessibleJTableCell82AccessibleTable accessibleTable = (AccessibleTable) table83.getAccessibleContext();84AccessibleTable header = accessibleTable.getAccessibleColumnHeader();85AccessibleComponent accessibleComp1 = (AccessibleComponent) header86.getAccessibleAt(0, 0);87// getLocation() must be null according to its javadoc and no exception88// is thrown89if (null != accessibleComp1.getLocationOnScreen()) {90throw new RuntimeException(91"JTable$AccessibleJTable$AccessibleJTableHeaderCell."92+ "getLocation() must be null");93}9495JComponent.AccessibleJComponent accessibleJComponent =96(JComponent.AccessibleJComponent) table.getAccessibleContext();97AccessibleComponent accessibleComp2 = (AccessibleComponent)98accessibleJComponent.getAccessibleChild(3);99// getLocation() must be null according to its javadoc and no exception100// is thrown101if (null != accessibleComp2.getLocationOnScreen()) {102throw new RuntimeException("JTable$AccessibleJTable$"103+ "AccessibleJTableCell.getLocation() must be null");104}105106}107}108109110