< prev index next >

test/jdk/com/sun/java/swing/plaf/windows/AltFocusIssueTest.java

Print this page
rev 53773 : 8219095: [testbug] Add @key headful to com/sun/java/swing/plaf/windows/AltFocusIssueTest.java
   1 /*
   2  * Copyright (c) 2018, 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 8211987
  26    @requires (os.family == "windows")
  27    @summary Verify if Menu bar gets input focus even if Alt-released event is consumed.
  28    @modules java.desktop/com.sun.java.swing.plaf.windows
  29    @run main AltFocusIssueTest
  30 */


  31 
  32 import java.awt.event.KeyAdapter;
  33 import java.awt.event.KeyEvent;
  34 import java.lang.reflect.InvocationTargetException;
  35 import java.awt.Robot;
  36 import javax.swing.JFrame;
  37 import javax.swing.JMenu;
  38 import javax.swing.JMenuBar;
  39 import javax.swing.JMenuItem;
  40 import javax.swing.JTextArea;
  41 import javax.swing.SwingUtilities;
  42 import javax.swing.UIManager;
  43 import javax.swing.UnsupportedLookAndFeelException;
  44 
  45 /**
  46  * Try to demonstrate the wrong behavior
  47  */
  48 public class AltFocusIssueTest {
  49 
  50     /**


 128             @Override
 129             public void keyReleased(KeyEvent e) {
 130                 if (e.getKeyCode() == KeyEvent.VK_ALT) {
 131                     /*
 132                      * This is where I need to do special handling of the Alt-released event.
 133                      * After, nobody else must react to this event, thus I consume it.
 134                      */
 135                     e.consume();
 136                 }
 137             }
 138         });
 139 
 140         frame.setSize(400, 300);
 141         frame.setVisible(true);
 142     }
 143 
 144     public static void main(String[] args) throws Exception {
 145         try {
 146             testAltEvents();
 147         } finally {

 148             SwingUtilities.invokeAndWait(() -> frame.dispose());

 149         }
 150     }
 151 }
   1 /*
   2  * Copyright (c) 2018, 2019, 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  * @bug 8211987
  27  * @key headful
  28  * @requires (os.family == "windows")
  29  * @summary Verify if Menu bar gets input focus even if Alt-released event is consumed.
  30  * @modules java.desktop/com.sun.java.swing.plaf.windows
  31  * @run main AltFocusIssueTest
  32  */
  33 
  34 import java.awt.event.KeyAdapter;
  35 import java.awt.event.KeyEvent;
  36 import java.lang.reflect.InvocationTargetException;
  37 import java.awt.Robot;
  38 import javax.swing.JFrame;
  39 import javax.swing.JMenu;
  40 import javax.swing.JMenuBar;
  41 import javax.swing.JMenuItem;
  42 import javax.swing.JTextArea;
  43 import javax.swing.SwingUtilities;
  44 import javax.swing.UIManager;
  45 import javax.swing.UnsupportedLookAndFeelException;
  46 
  47 /**
  48  * Try to demonstrate the wrong behavior
  49  */
  50 public class AltFocusIssueTest {
  51 
  52     /**


 130             @Override
 131             public void keyReleased(KeyEvent e) {
 132                 if (e.getKeyCode() == KeyEvent.VK_ALT) {
 133                     /*
 134                      * This is where I need to do special handling of the Alt-released event.
 135                      * After, nobody else must react to this event, thus I consume it.
 136                      */
 137                     e.consume();
 138                 }
 139             }
 140         });
 141 
 142         frame.setSize(400, 300);
 143         frame.setVisible(true);
 144     }
 145 
 146     public static void main(String[] args) throws Exception {
 147         try {
 148             testAltEvents();
 149         } finally {
 150             if (frame != null) {
 151                 SwingUtilities.invokeAndWait(() -> frame.dispose());
 152             }
 153         }
 154     }
 155 }
< prev index next >