DisabledComponent.java revision 14851:980da45565c8
1/* 2 * Copyright (c) 2009, 2016, 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/* 25 @test 26 @key headful 27 @bug 6847958 28 @summary MouseWheel event is getting triggered for the disabled Textarea in jdk7 b60 pit build. 29 @author Dmitry Cherepanov: area=awt.event 30 @library ../../../regtesthelpers 31 @build Util 32 @run main DisabledComponent 33*/ 34 35/** 36 * DisabledComponent.java 37 * 38 * summary: Tests that wheel events aren't coming on disabled component 39 */ 40 41import java.awt.*; 42import java.awt.event.*; 43 44import test.java.awt.regtesthelpers.Util; 45 46public class DisabledComponent 47{ 48 49 private static volatile boolean passed = true; 50 51 public static void main(String []s) throws Exception 52 { 53 Frame frame = new Frame(); 54 frame.setBounds(100,100,400,400); 55 frame.setLayout(new FlowLayout()); 56 57 TextArea textArea = new TextArea("TextArea", 6, 15); 58 frame.add(textArea); 59 60 List list = new List(3); 61 list.add("1"); 62 list.add("2"); 63 list.add("3"); 64 frame.add(list); 65 66 MouseWheelListener listener = new MouseWheelListener(){ 67 @Override 68 public void mouseWheelMoved(MouseWheelEvent mwe){ 69 System.err.println(mwe); 70 passed = false; 71 } 72 }; 73 74 Robot robot = new Robot(); 75 76 77 list.addMouseWheelListener(listener); 78 textArea.addMouseWheelListener(listener); 79 80 frame.setVisible(true); 81 robot.waitForIdle(); 82 83 // point and wheel on the list 84 Util.pointOnComp(list, robot); 85 robot.waitForIdle(); 86 87 robot.mouseWheel(2); 88 robot.waitForIdle(); 89 90 // disable the text area 91 System.err.println(" disable text area "); 92 textArea.setEnabled(false); 93 passed = true; 94 95 // point and wheel on the text area 96 Util.pointOnComp(textArea, robot); 97 robot.waitForIdle(); 98 99 robot.mouseWheel(2); 100 robot.waitForIdle(); 101 102 if (!passed) { 103 throw new RuntimeException(" wrong wheel events "); 104 } 105 } 106} 107