2014-11-21 13:11:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
2016-07-07 14:21:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @key headful
|
2022-09-20 18:15:13 +00:00
|
|
|
* @bug 6559152 8294067
|
2016-07-07 14:21:45 +00:00
|
|
|
* @summary Checks that you can select an item in JComboBox with keyboard
|
|
|
|
* when it is a JTable cell editor.
|
|
|
|
* @run main bug6559152
|
|
|
|
*/
|
2014-11-21 13:11:03 +00:00
|
|
|
|
2022-09-20 18:15:13 +00:00
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Point;
|
|
|
|
import java.awt.Robot;
|
|
|
|
import java.awt.event.InputEvent;
|
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
|
2020-12-11 04:54:27 +00:00
|
|
|
import javax.swing.DefaultCellEditor;
|
2022-09-20 18:15:13 +00:00
|
|
|
import javax.swing.JComboBox;
|
2020-12-11 04:54:27 +00:00
|
|
|
import javax.swing.JComponent;
|
|
|
|
import javax.swing.JFrame;
|
2022-09-20 18:15:13 +00:00
|
|
|
import javax.swing.JTable;
|
2020-12-11 04:54:27 +00:00
|
|
|
import javax.swing.SwingUtilities;
|
2014-11-21 13:11:03 +00:00
|
|
|
import javax.swing.table.DefaultTableModel;
|
|
|
|
|
|
|
|
public class bug6559152 {
|
2020-12-11 04:54:27 +00:00
|
|
|
private static JFrame frame;
|
|
|
|
private static JComboBox cb;
|
|
|
|
private static Robot robot;
|
|
|
|
private static Point p = null;
|
2022-09-20 18:15:13 +00:00
|
|
|
private static Dimension d;
|
2014-11-21 13:11:03 +00:00
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
2020-12-11 04:54:27 +00:00
|
|
|
robot = new Robot();
|
|
|
|
robot.setAutoDelay(100);
|
2014-11-21 13:11:03 +00:00
|
|
|
try {
|
2020-12-11 04:54:27 +00:00
|
|
|
SwingUtilities.invokeAndWait(() -> setupUI());
|
|
|
|
blockTillDisplayed(cb);
|
|
|
|
robot.waitForIdle();
|
|
|
|
robot.delay(1000);
|
|
|
|
test();
|
2014-11-21 13:11:03 +00:00
|
|
|
} finally {
|
2020-12-11 04:54:27 +00:00
|
|
|
if (frame != null) {
|
|
|
|
SwingUtilities.invokeAndWait(() -> frame.dispose());
|
2014-11-21 13:11:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-11 04:54:27 +00:00
|
|
|
static void blockTillDisplayed(JComponent comp) throws Exception {
|
|
|
|
while (p == null) {
|
|
|
|
try {
|
|
|
|
SwingUtilities.invokeAndWait(() -> {
|
|
|
|
p = comp.getLocationOnScreen();
|
2022-09-20 18:15:13 +00:00
|
|
|
d = comp.getSize();
|
2020-12-11 04:54:27 +00:00
|
|
|
});
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException ie) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void setupUI() {
|
2014-11-21 13:11:03 +00:00
|
|
|
frame = new JFrame();
|
|
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
|
|
DefaultTableModel model = new DefaultTableModel(1, 1);
|
|
|
|
JTable table = new JTable(model);
|
|
|
|
|
|
|
|
cb = new JComboBox(new String[]{"one", "two", "three"});
|
|
|
|
cb.setEditable(true);
|
|
|
|
table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(cb));
|
|
|
|
frame.add(cb);
|
|
|
|
|
|
|
|
frame.pack();
|
2020-12-11 04:54:27 +00:00
|
|
|
frame.setLocationRelativeTo(null);
|
2021-01-22 08:02:56 +00:00
|
|
|
frame.setVisible(true);
|
2014-11-21 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 04:54:27 +00:00
|
|
|
private static void test() throws Exception {
|
2022-09-20 18:15:13 +00:00
|
|
|
robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);
|
2021-01-22 08:02:56 +00:00
|
|
|
robot.waitForIdle();
|
2020-12-11 04:54:27 +00:00
|
|
|
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
|
|
|
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
2014-11-21 13:11:03 +00:00
|
|
|
robot.waitForIdle();
|
2021-01-22 08:02:56 +00:00
|
|
|
testImpl();
|
2014-11-21 13:11:03 +00:00
|
|
|
checkResult();
|
|
|
|
}
|
|
|
|
|
2020-12-11 04:54:27 +00:00
|
|
|
private static void testImpl() throws Exception {
|
|
|
|
robot.keyPress(KeyEvent.VK_DOWN);
|
|
|
|
robot.keyRelease(KeyEvent.VK_DOWN);
|
2014-11-21 13:11:03 +00:00
|
|
|
robot.waitForIdle();
|
2020-12-11 04:54:27 +00:00
|
|
|
robot.keyPress(KeyEvent.VK_DOWN);
|
|
|
|
robot.keyRelease(KeyEvent.VK_DOWN);
|
2014-11-21 13:11:03 +00:00
|
|
|
robot.waitForIdle();
|
2020-12-11 04:54:27 +00:00
|
|
|
robot.keyPress(KeyEvent.VK_ENTER);
|
|
|
|
robot.keyRelease(KeyEvent.VK_ENTER);
|
2021-01-22 08:02:56 +00:00
|
|
|
robot.waitForIdle();
|
2014-11-21 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 04:54:27 +00:00
|
|
|
private static void checkResult() {
|
2014-11-21 13:11:03 +00:00
|
|
|
if (cb.getSelectedItem().equals("two")) {
|
|
|
|
System.out.println("Test passed");
|
|
|
|
} else {
|
|
|
|
System.out.println("Test failed");
|
|
|
|
throw new RuntimeException("Cannot select an item " +
|
|
|
|
"from popup with the ENTER key.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|