0N/A/*
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A */
2362N/A
0N/A/* @test
0N/A * @bug 4743225
0N/A * @summary Size of JComboBox list is wrong when list is populated via PopupMenuListener
0N/A * @author Alexander Potochkin
0N/A */
0N/A
0N/Aimport sun.awt.SunToolkit;
0N/A
0N/Aimport javax.accessibility.AccessibleContext;
0N/Aimport javax.swing.JComboBox;
0N/Aimport javax.swing.JFrame;
0N/Aimport javax.swing.SwingUtilities;
0N/Aimport javax.swing.event.PopupMenuEvent;
0N/Aimport javax.swing.event.PopupMenuListener;
0N/Aimport javax.swing.plaf.basic.BasicComboPopup;
0N/Aimport java.awt.FlowLayout;
0N/Aimport java.awt.Point;
0N/Aimport java.awt.Robot;
0N/Aimport java.awt.Toolkit;
0N/Aimport java.awt.event.InputEvent;
0N/A
0N/Apublic class bug4743225 extends JFrame {
0N/A
0N/A private static JComboBox cb;
0N/A private static volatile boolean flag;
0N/A
0N/A public bug4743225() {
0N/A setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
0N/A setLayout(new FlowLayout());
0N/A cb = new JComboBox(new Object[] {"one", "two", "three"});
0N/A cb.addPopupMenuListener(new PopupMenuListener() {
0N/A public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
0N/A cb.addItem("Test");
0N/A }
0N/A
0N/A public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
0N/A }
0N/A
0N/A public void popupMenuCanceled(PopupMenuEvent e) {
0N/A }
0N/A });
0N/A add(cb);
0N/A pack();
0N/A }
0N/A
0N/A public static BasicComboPopup getPopup() {
0N/A AccessibleContext c = cb.getAccessibleContext();
0N/A for(int i = 0; i < c.getAccessibleChildrenCount(); i ++) {
0N/A if (c.getAccessibleChild(i) instanceof BasicComboPopup) {
0N/A return (BasicComboPopup) c.getAccessibleChild(i);
0N/A }
0N/A }
0N/A throw new AssertionError("No BasicComboPopup found");
0N/A }
0N/A
0N/A public static void main(String... args) throws Exception {
0N/A
0N/A Robot robot = new Robot();
0N/A robot.setAutoDelay(20);
0N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
0N/A
0N/A SwingUtilities.invokeAndWait(new Runnable() {
0N/A public void run() {
0N/A new bug4743225().setVisible(true);
0N/A }
0N/A });
0N/A toolkit.realSync();
0N/A
0N/A // calling this method from main thread is ok
0N/A Point point = cb.getLocationOnScreen();
0N/A robot.mouseMove(point.x + 10, point.y + 10);
0N/A robot.mousePress(InputEvent.BUTTON1_MASK);
0N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
0N/A toolkit.realSync();
0N/A
0N/A SwingUtilities.invokeAndWait(new Runnable() {
0N/A public void run() {
0N/A if(getPopup().getList().getLastVisibleIndex() == 3) {
0N/A flag = true;
0N/A }
0N/A }
0N/A });
0N/A
0N/A if (!flag) {
0N/A throw new RuntimeException("The ComboBox popup wasn't correctly updated");
0N/A }
0N/A }
0N/A}
0N/A