author | alexp |
Thu, 29 Jul 2010 19:34:03 +0400 | |
changeset 6103 | a2498232c8f2 |
child 28071 | 3acb75b8df45 |
permissions | -rw-r--r-- |
6103
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
1 |
/* |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
4 |
* |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
8 |
* |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
13 |
* accompanied this code). |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
14 |
* |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
18 |
* |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
21 |
* questions. |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
22 |
*/ |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
23 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
24 |
/* @test |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
25 |
* @bug 4743225 |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
26 |
* @summary Size of JComboBox list is wrong when list is populated via PopupMenuListener |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
27 |
* @author Alexander Potochkin |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
28 |
*/ |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
29 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
30 |
import sun.awt.SunToolkit; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
31 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
32 |
import javax.accessibility.AccessibleContext; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
33 |
import javax.swing.JComboBox; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
34 |
import javax.swing.JFrame; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
35 |
import javax.swing.SwingUtilities; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
36 |
import javax.swing.event.PopupMenuEvent; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
37 |
import javax.swing.event.PopupMenuListener; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
38 |
import javax.swing.plaf.basic.BasicComboPopup; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
39 |
import java.awt.FlowLayout; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
40 |
import java.awt.Point; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
41 |
import java.awt.Robot; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
42 |
import java.awt.Toolkit; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
43 |
import java.awt.event.InputEvent; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
44 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
45 |
public class bug4743225 extends JFrame { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
46 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
47 |
private static JComboBox cb; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
48 |
private static volatile boolean flag; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
49 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
50 |
public bug4743225() { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
51 |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
52 |
setLayout(new FlowLayout()); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
53 |
cb = new JComboBox(new Object[] {"one", "two", "three"}); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
54 |
cb.addPopupMenuListener(new PopupMenuListener() { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
55 |
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
56 |
cb.addItem("Test"); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
57 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
58 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
59 |
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
60 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
61 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
62 |
public void popupMenuCanceled(PopupMenuEvent e) { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
63 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
64 |
}); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
65 |
add(cb); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
66 |
pack(); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
67 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
68 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
69 |
public static BasicComboPopup getPopup() { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
70 |
AccessibleContext c = cb.getAccessibleContext(); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
71 |
for(int i = 0; i < c.getAccessibleChildrenCount(); i ++) { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
72 |
if (c.getAccessibleChild(i) instanceof BasicComboPopup) { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
73 |
return (BasicComboPopup) c.getAccessibleChild(i); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
74 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
75 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
76 |
throw new AssertionError("No BasicComboPopup found"); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
77 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
78 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
79 |
public static void main(String... args) throws Exception { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
80 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
81 |
Robot robot = new Robot(); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
82 |
robot.setAutoDelay(20); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
83 |
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
84 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
85 |
SwingUtilities.invokeAndWait(new Runnable() { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
86 |
public void run() { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
87 |
new bug4743225().setVisible(true); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
88 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
89 |
}); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
90 |
toolkit.realSync(); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
91 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
92 |
// calling this method from main thread is ok |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
93 |
Point point = cb.getLocationOnScreen(); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
94 |
robot.mouseMove(point.x + 10, point.y + 10); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
95 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
96 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
97 |
toolkit.realSync(); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
98 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
99 |
SwingUtilities.invokeAndWait(new Runnable() { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
100 |
public void run() { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
101 |
if(getPopup().getList().getLastVisibleIndex() == 3) { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
102 |
flag = true; |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
103 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
104 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
105 |
}); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
106 |
|
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
107 |
if (!flag) { |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
108 |
throw new RuntimeException("The ComboBox popup wasn't correctly updated"); |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
109 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
110 |
} |
a2498232c8f2
4743225: Size of JComboBox list is wrong when list is populated via PopupMenuListener
alexp
parents:
diff
changeset
|
111 |
} |