< prev index next >

test/jdk/javax/swing/JTabbedPane/4624207/bug4624207.java

Print this page
rev 51542 : 8210039: move OSInfo to top level testlibrary
Reviewed-by: duke


  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 4624207
  28  * @summary JTabbedPane mnemonics don't work from outside the tabbed pane
  29  * @author Oleg Mokhovikov
  30  * @library ../../../../lib/testlibrary
  31  * @library ../../regtesthelpers
  32  * @build Util jdk.testlibrary.OSInfo
  33  * @run main bug4624207
  34  */
  35 import javax.swing.*;
  36 import javax.swing.event.ChangeEvent;
  37 import javax.swing.event.ChangeListener;
  38 import java.awt.*;
  39 import java.awt.event.FocusEvent;
  40 import java.awt.event.FocusListener;
  41 import java.awt.event.KeyEvent;
  42 
  43 import jdk.testlibrary.OSInfo;
  44 
  45 public class bug4624207 implements ChangeListener, FocusListener {
  46 
  47     private static volatile boolean stateChanged = false;
  48     private static volatile boolean focusGained = false;
  49     private static JTextField txtField;
  50     private static JTabbedPane tab;
  51     private static Object listener;
  52 
  53     public void stateChanged(ChangeEvent e) {
  54         System.out.println("stateChanged called");
  55         stateChanged = true;
  56     }
  57 
  58     public void focusGained(FocusEvent e) {
  59         System.out.println("focusGained called");
  60         focusGained = true;
  61     }
  62 
  63     public void focusLost(FocusEvent e) {


  84                 txtField.requestFocus();
  85             }
  86         });
  87 
  88         robot.waitForIdle();
  89 
  90         if (!focusGained) {
  91             throw new RuntimeException("Couldn't gain focus for text field");
  92         }
  93 
  94         SwingUtilities.invokeAndWait(new Runnable() {
  95 
  96             public void run() {
  97                 tab.addChangeListener((ChangeListener) listener);
  98                 txtField.removeFocusListener((FocusListener) listener);
  99             }
 100         });
 101 
 102         robot.waitForIdle();
 103 
 104         if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
 105             Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_B);
 106         } else {
 107             Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_B);
 108         }
 109 
 110         robot.waitForIdle();
 111 
 112         if (!stateChanged || tab.getSelectedIndex() != 1) {
 113             throw new RuntimeException("JTabbedPane mnemonics don't work from outside the tabbed pane");
 114         }
 115     }
 116 
 117     private static void createAndShowGUI() {
 118         tab = new JTabbedPane();
 119         tab.add("Tab1", new JButton("Button1"));
 120         tab.add("Tab2", new JButton("Button2"));
 121         tab.setMnemonicAt(0, KeyEvent.VK_T);
 122         tab.setMnemonicAt(1, KeyEvent.VK_B);
 123 
 124         JFrame frame = new JFrame();


  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 4624207
  28  * @summary JTabbedPane mnemonics don't work from outside the tabbed pane
  29  * @author Oleg Mokhovikov
  30  * @library /test/lib
  31  * @library ../../regtesthelpers
  32  * @build Util jdk.test.lib.Platform
  33  * @run main bug4624207
  34  */
  35 import javax.swing.*;
  36 import javax.swing.event.ChangeEvent;
  37 import javax.swing.event.ChangeListener;
  38 import java.awt.*;
  39 import java.awt.event.FocusEvent;
  40 import java.awt.event.FocusListener;
  41 import java.awt.event.KeyEvent;
  42 
  43 import jdk.test.lib.Platform;
  44 
  45 public class bug4624207 implements ChangeListener, FocusListener {
  46 
  47     private static volatile boolean stateChanged = false;
  48     private static volatile boolean focusGained = false;
  49     private static JTextField txtField;
  50     private static JTabbedPane tab;
  51     private static Object listener;
  52 
  53     public void stateChanged(ChangeEvent e) {
  54         System.out.println("stateChanged called");
  55         stateChanged = true;
  56     }
  57 
  58     public void focusGained(FocusEvent e) {
  59         System.out.println("focusGained called");
  60         focusGained = true;
  61     }
  62 
  63     public void focusLost(FocusEvent e) {


  84                 txtField.requestFocus();
  85             }
  86         });
  87 
  88         robot.waitForIdle();
  89 
  90         if (!focusGained) {
  91             throw new RuntimeException("Couldn't gain focus for text field");
  92         }
  93 
  94         SwingUtilities.invokeAndWait(new Runnable() {
  95 
  96             public void run() {
  97                 tab.addChangeListener((ChangeListener) listener);
  98                 txtField.removeFocusListener((FocusListener) listener);
  99             }
 100         });
 101 
 102         robot.waitForIdle();
 103 
 104         if (Platform.isOSX()) {
 105             Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_B);
 106         } else {
 107             Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_B);
 108         }
 109 
 110         robot.waitForIdle();
 111 
 112         if (!stateChanged || tab.getSelectedIndex() != 1) {
 113             throw new RuntimeException("JTabbedPane mnemonics don't work from outside the tabbed pane");
 114         }
 115     }
 116 
 117     private static void createAndShowGUI() {
 118         tab = new JTabbedPane();
 119         tab.add("Tab1", new JButton("Button1"));
 120         tab.add("Tab2", new JButton("Button2"));
 121         tab.setMnemonicAt(0, KeyEvent.VK_T);
 122         tab.setMnemonicAt(1, KeyEvent.VK_B);
 123 
 124         JFrame frame = new JFrame();
< prev index next >