1 /* 2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* 24 @test 25 @bug 4255631 26 @summary Solaris: Size returned by Choice.getSize() does not match actual size 27 @author Andrei Dmitriev : area=Choice 28 run main GetSizeTest.html 29 */ 30 31 import java.awt.*; 32 import java.awt.event.*; 33 34 public class GetSizeTest { 35 36 static String []s = {"Choice 1", 37 "Choice 2", 38 "unselected choices", 39 "what choices do I have?", 40 "Will I pick the same thing in the future?", 41 }; 42 static boolean passed = false; 43 static Robot robot = null; 44 45 public static void main(String args[]) 46 { 47 try { 48 robot = new Robot(); 49 robot.setAutoDelay(50); 50 51 Frame f = new Frame("choice test"); 52 53 Panel p = new Panel(); 54 p.setLayout(null); 55 56 Choice c = new Choice(); 57 for (int i = 0; i < s.length; i++) 58 c.addItem(s[i]); 59 60 c.addMouseListener(new MouseAdapter() { 61 public void mouseReleased(MouseEvent e) { 62 System.err.println("Test passed"); 63 passed = true; 64 } 65 }); 66 67 p.add(c); 68 69 f.add(p); 70 71 f.setSize(300, 300); 72 73 f.addWindowListener(new WindowAdapter() { 74 public void windowClosing(WindowEvent we) { 75 System.err.println("Test passed"); 76 passed = true; 77 } 78 }); 79 80 f.setVisible(true); 81 82 c.setSize(200, 200); 83 f.validate(); 84 85 robot.waitForIdle(); 86 87 Point pt = c.getLocationOnScreen(); 88 robot.mouseMove(pt.x + c.getWidth() - 10, pt.y + c.getHeight() / 2); 89 robot.waitForIdle(); 90 robot.mousePress(InputEvent.BUTTON2_MASK); 91 robot.mouseRelease(InputEvent.BUTTON2_MASK); 92 robot.waitForIdle(); 93 } catch (Throwable e) { 94 if (robot == null){ 95 throw new RuntimeException( "Test failed.Unable to initialize Robot "+e); 96 } 97 throw new RuntimeException( "Test failed due to thrown exception "+e); 98 } 99 if (!passed) { 100 throw new RuntimeException( "Timeout. Choice component size is not actual size." ); 101 } 102 System.err.println("Test passed."); 103 } 104 }