Path: blob/master/test/jdk/java/awt/Choice/ChoiceFromMaximizedFrame/ChoiceFromMaximizedFrame.java
41152 views
/*1* Copyright (c) 2019, 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 823438627* @requires (os.family == "mac")28* @summary [macos] NPE was thrown at expanding Choice from maximized frame29* @run main ChoiceFromMaximizedFrame30*/3132import java.awt.BorderLayout;33import java.awt.Canvas;34import java.awt.Choice;35import java.awt.Frame;36import java.awt.GraphicsConfiguration;37import java.awt.GraphicsEnvironment;38import java.awt.Insets;39import java.awt.Panel;40import java.awt.Rectangle;41import java.awt.Robot;42import java.awt.Toolkit;43import java.awt.event.KeyEvent;4445public class ChoiceFromMaximizedFrame46{47static public void main(String args[]) throws Exception48{49Frame f = new Frame("ChoiceTest");50try {51Panel p =new Panel(new BorderLayout());52Choice choice = new Choice();53choice.addItem("aaa");54choice.addItem("bbb");55p.add("North",choice);56p.add("Center",new Canvas());57f.add(p);5859GraphicsConfiguration gc = GraphicsEnvironment60.getLocalGraphicsEnvironment()61.getDefaultScreenDevice().getDefaultConfiguration();62Rectangle bounds = gc.getBounds();63Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);64int x = bounds.x + insets.left;65int y = bounds.y + insets.top;66int width = bounds.width - insets.left - insets.right;67int height = bounds.height - insets.top - insets.bottom;68Rectangle rect = new Rectangle(x, y, width, height);69f.pack();70f.setBounds(rect);71f.setVisible(true);7273Robot robot = new Robot();74robot.waitForIdle();75robot.keyPress(KeyEvent.VK_SPACE);76robot.keyRelease(KeyEvent.VK_SPACE);77robot.delay(1000);78} finally {79f.dispose();80}81}82}838485