Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JComboBox/8072767/bug8072767.java
41153 views
1
/*
2
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.awt.Point;
25
import java.awt.Rectangle;
26
import java.awt.Robot;
27
import java.awt.event.InputEvent;
28
import java.awt.event.KeyEvent;
29
import javax.swing.DefaultCellEditor;
30
import javax.swing.JComboBox;
31
import javax.swing.JFrame;
32
import javax.swing.JTable;
33
import javax.swing.SwingUtilities;
34
35
/**
36
* @test
37
* @key headful
38
* @bug 8072767
39
* @summary DefaultCellEditor for comboBox creates ActionEvent with wrong source
40
* object
41
* @run main bug8072767
42
*/
43
44
public class bug8072767 {
45
46
private static final String TEST1 = "Test";
47
private static final String TEST2 = TEST1 + 1;
48
49
private static JFrame frame;
50
private static JTable table;
51
private static volatile Point point;
52
private static boolean testPass;
53
54
public static void main(String[] args) throws Exception {
55
Robot robot = new Robot();
56
robot.setAutoDelay(100);
57
SwingUtilities.invokeAndWait(bug8072767::createAndShowGUI);
58
robot.waitForIdle();
59
robot.delay(1000);
60
SwingUtilities.invokeAndWait(() -> {
61
point = table.getLocationOnScreen();
62
Rectangle rect = table.getCellRect(0, 0, true);
63
point.translate(rect.width / 2, rect.height / 2);
64
});
65
robot.mouseMove(point.x, point.y);
66
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
67
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
68
robot.waitForIdle();
69
70
robot.keyPress(KeyEvent.VK_1);
71
robot.keyRelease(KeyEvent.VK_1);
72
robot.waitForIdle();
73
74
SwingUtilities.invokeAndWait(() -> {
75
point = frame.getLocationOnScreen();
76
point.translate(frame.getWidth() / 2, frame.getHeight() / 2);
77
});
78
79
robot.mouseMove(point.x, point.y);
80
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
81
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
82
robot.waitForIdle();
83
84
SwingUtilities.invokeAndWait(() -> {
85
testPass = TEST2.equals(table.getValueAt(0, 0));
86
frame.dispose();
87
});
88
89
if (!testPass) {
90
throw new RuntimeException("Table cell is not edited!");
91
}
92
}
93
94
private static void createAndShowGUI() {
95
frame = new JFrame();
96
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
97
frame.setSize(200, 200);
98
99
table = new JTable(
100
new String[][]{{TEST1}}, new String[]{"Header"});
101
JComboBox<String> comboBox = new JComboBox<>();
102
comboBox.setEditable(true);
103
table.getColumnModel().getColumn(0).setCellEditor(
104
new DefaultCellEditor(comboBox));
105
frame.getContentPane().add(table);
106
frame.setVisible(true);
107
frame.setLocationRelativeTo(null);
108
}
109
}
110
111