Path: blob/master/test/jdk/javax/swing/JInternalFrame/Test6505027.java
41152 views
/*1* Copyright (c) 2009, 2013, 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 650502727* @summary Tests focus problem inside internal frame28* @author Sergey Malenkov29* @library ..30*/3132import java.awt.AWTException;33import java.awt.BorderLayout;34import java.awt.Component;35import java.awt.Container;36import java.awt.KeyboardFocusManager;37import java.awt.Point;38import java.awt.Robot;39import java.awt.event.InputEvent;40import javax.swing.DefaultCellEditor;41import javax.swing.JComboBox;42import javax.swing.JDesktopPane;43import javax.swing.JFrame;44import javax.swing.JInternalFrame;45import javax.swing.JScrollPane;46import javax.swing.JTable;47import javax.swing.JTextField;48import javax.swing.SwingUtilities;49import javax.swing.table.DefaultTableModel;50import javax.swing.table.TableColumn;5152public class Test6505027 {5354private static final boolean INTERNAL = true;55private static final boolean TERMINATE = true;5657private static final int WIDTH = 450;58private static final int HEIGHT = 200;59private static final int OFFSET = 10;6061private static final String[] COLUMNS = { "Size", "Shape" }; // NON-NLS: column names62private static final String[] ITEMS = { "a", "b", "c", "d" }; // NON-NLS: combobox content63private static final String KEY = "terminateEditOnFocusLost"; // NON-NLS: property name6465public static void main(String[] args) throws Throwable {66SwingTest.start(Test6505027.class);67}6869private final JTable table = new JTable(new DefaultTableModel(COLUMNS, 2));7071public Test6505027(JFrame main) {72Container container = main;73if (INTERNAL) {74JInternalFrame frame = new JInternalFrame();75frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);76frame.setVisible(true);7778JDesktopPane desktop = new JDesktopPane();79desktop.add(frame, new Integer(1));8081container.add(desktop);82container = frame;83}84if (TERMINATE) {85this.table.putClientProperty(KEY, Boolean.TRUE);86}87TableColumn column = this.table.getColumn(COLUMNS[1]);88column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));8990container.add(BorderLayout.NORTH, new JTextField());91container.add(BorderLayout.CENTER, new JScrollPane(this.table));92}9394public void press() throws AWTException {95Point point = this.table.getCellRect(1, 1, false).getLocation();96SwingUtilities.convertPointToScreen(point, this.table);9798Robot robot = new Robot();99robot.setAutoDelay(50);100robot.mouseMove(point.x + 1, point.y + 1);101robot.mousePress(InputEvent.BUTTON1_MASK);102robot.mouseRelease(InputEvent.BUTTON1_MASK);103}104105public static void validate() {106Component component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();107if (!component.getClass().equals(JComboBox.class)) {108throw new Error("unexpected focus owner: " + component);109}110}111}112113114