Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JInternalFrame/Test6505027.java
38839 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* @bug 650502726* @summary Tests focus problem inside internal frame27* @author Sergey Malenkov28* @library ..29*/3031import java.awt.AWTException;32import java.awt.BorderLayout;33import java.awt.Component;34import java.awt.Container;35import java.awt.KeyboardFocusManager;36import java.awt.Point;37import java.awt.Robot;38import java.awt.event.InputEvent;39import javax.swing.DefaultCellEditor;40import javax.swing.JComboBox;41import javax.swing.JDesktopPane;42import javax.swing.JFrame;43import javax.swing.JInternalFrame;44import javax.swing.JScrollPane;45import javax.swing.JTable;46import javax.swing.JTextField;47import javax.swing.SwingUtilities;48import javax.swing.table.DefaultTableModel;49import javax.swing.table.TableColumn;5051public class Test6505027 {5253private static final boolean INTERNAL = true;54private static final boolean TERMINATE = true;5556private static final int WIDTH = 450;57private static final int HEIGHT = 200;58private static final int OFFSET = 10;5960private static final String[] COLUMNS = { "Size", "Shape" }; // NON-NLS: column names61private static final String[] ITEMS = { "a", "b", "c", "d" }; // NON-NLS: combobox content62private static final String KEY = "terminateEditOnFocusLost"; // NON-NLS: property name6364public static void main(String[] args) throws Throwable {65SwingTest.start(Test6505027.class);66}6768private final JTable table = new JTable(new DefaultTableModel(COLUMNS, 2));6970public Test6505027(JFrame main) {71Container container = main;72if (INTERNAL) {73JInternalFrame frame = new JInternalFrame();74frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);75frame.setVisible(true);7677JDesktopPane desktop = new JDesktopPane();78desktop.add(frame, new Integer(1));7980container.add(desktop);81container = frame;82}83if (TERMINATE) {84this.table.putClientProperty(KEY, Boolean.TRUE);85}86TableColumn column = this.table.getColumn(COLUMNS[1]);87column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));8889container.add(BorderLayout.NORTH, new JTextField());90container.add(BorderLayout.CENTER, new JScrollPane(this.table));91}9293public void press() throws AWTException {94Point point = this.table.getCellRect(1, 1, false).getLocation();95SwingUtilities.convertPointToScreen(point, this.table);9697Robot robot = new Robot();98robot.setAutoDelay(50);99robot.mouseMove(point.x + 1, point.y + 1);100robot.mousePress(InputEvent.BUTTON1_MASK);101robot.mouseRelease(InputEvent.BUTTON1_MASK);102}103104public static void validate() {105Component component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();106if (!component.getClass().equals(JComboBox.class)) {107throw new Error("unexpected focus owner: " + component);108}109}110}111112113