Path: blob/master/test/jdk/java/awt/Choice/RemoveAllShrinkTest/RemoveAllShrinkTest.java
41152 views
/*1* Copyright (c) 2014, 2020, 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@key headful26@bug 4851798 8041896 822512627@summary Tests Choice List shrinks after removeAll28@run main RemoveAllShrinkTest29*/3031import java.awt.BorderLayout;32import java.awt.Choice;33import java.awt.Color;34import java.awt.Frame;35import java.awt.Panel;36import java.awt.Point;37import java.awt.Robot;38import java.awt.event.InputEvent;3940public class RemoveAllShrinkTest {4142public static void main(String[] args) {43Frame f = new Frame();44try {45Choice choice = new Choice();4647for (int i = 0; i < 10; ++i) {48choice.addItem("Item " + i);49}5051f.add(choice, BorderLayout.NORTH);52Panel panel = new Panel();53panel.setBackground(Color.RED);54f.add(panel);5556f.setSize(200, 200);57f.setLocationRelativeTo(null);58f.setVisible(true);59f.toFront();6061choice.removeAll();6263try {64Robot robot = new Robot();65robot.setAutoWaitForIdle(true);66robot.setAutoDelay(50);6768robot.waitForIdle();69Thread.sleep(200);7071Point pt = choice.getLocationOnScreen();72robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight() / 2,73pt.y + choice.getHeight() / 2);74robot.mousePress(InputEvent.BUTTON1_MASK);75robot.mouseRelease(InputEvent.BUTTON1_MASK);7677Thread.sleep(400);7879Point pt1 = panel.getLocationOnScreen();8081Color color = robot.getPixelColor(pt1.x + panel.getWidth() / 2,82pt1.y + panel.getHeight() / 2);8384if (!color.equals(Color.RED)) {85throw new RuntimeException("RemoveAllShrinkTest failed. " + color);86}87} catch (Exception e) {88throw new RuntimeException("The test was not completed.\n\n" + e);89}90} finally {91f.dispose();92}93}94}95969798