Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Choice/RemoveAllShrinkTest/RemoveAllShrinkTest.java
47854 views
/*1* Copyright (c) 2014, 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 4851798 804189626@summary Tests Choice List shrinks after removeAll27@run main RemoveAllShrinkTest28*/2930import java.awt.*;31import java.awt.event.*;323334public class RemoveAllShrinkTest {3536public static void main(String[] args) {37Frame f = new Frame();38Choice choice = new Choice();3940for (int i = 0; i < 10; ++i) {41choice.addItem("Item " + i);42}4344f.add(choice, BorderLayout.NORTH);45Panel panel = new Panel();46panel.setBackground(Color.RED);47f.add(panel);4849f.setSize(200, 200);50f.setVisible(true);51f.toFront();5253choice.removeAll();5455try {56Robot robot = new Robot();57robot.setAutoWaitForIdle(true);58robot.setAutoDelay(50);5960robot.waitForIdle();61Thread.sleep(200);6263Point pt = choice.getLocationOnScreen();64robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight() / 2,65pt.y + choice.getHeight() / 2);66robot.mousePress(InputEvent.BUTTON1_MASK);67robot.mouseRelease(InputEvent.BUTTON1_MASK);6869Thread.sleep(400);7071Point pt1 = panel.getLocationOnScreen();7273Color color = robot.getPixelColor(pt1.x + panel.getWidth() / 2,74pt1.y + panel.getHeight() / 2);7576if (!color.equals(Color.RED)) {77throw new RuntimeException("RemoveAllShrinkTest failed. " + color);78}79} catch (Exception e) {80throw new RuntimeException("The test was not completed.\n\n" + e);81}82}83}84858687