|  | 
| 1 | 1 | /* | 
| 2 |  | - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. | 
|  | 2 | + * Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved. | 
| 3 | 3 |  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 
| 4 | 4 |  * | 
| 5 | 5 |  * This code is free software; you can redistribute it and/or modify it | 
|  | 
| 25 | 25 |  * @test | 
| 26 | 26 |  * @key headful | 
| 27 | 27 |  * @bug 4624207 | 
|  | 28 | + * @requires (os.family != "mac") | 
| 28 | 29 |  * @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 | 30 |  * @run main bug4624207 | 
| 34 | 31 |  */ | 
| 35 |  | -import javax.swing.*; | 
| 36 |  | -import javax.swing.event.ChangeEvent; | 
| 37 |  | -import javax.swing.event.ChangeListener; | 
| 38 |  | -import java.awt.*; | 
|  | 32 | + | 
|  | 33 | +import java.awt.BorderLayout; | 
|  | 34 | +import java.awt.Robot; | 
| 39 | 35 | import java.awt.event.FocusEvent; | 
| 40 | 36 | import java.awt.event.FocusListener; | 
| 41 | 37 | import java.awt.event.KeyEvent; | 
| 42 | 38 | 
 | 
| 43 |  | -import jdk.test.lib.Platform; | 
|  | 39 | +import javax.swing.JButton; | 
|  | 40 | +import javax.swing.JFrame; | 
|  | 41 | +import javax.swing.JTabbedPane; | 
|  | 42 | +import javax.swing.JTextField; | 
|  | 43 | +import javax.swing.SwingUtilities; | 
|  | 44 | +import javax.swing.event.ChangeEvent; | 
|  | 45 | +import javax.swing.event.ChangeListener; | 
| 44 | 46 | 
 | 
| 45 | 47 | public class bug4624207 implements ChangeListener, FocusListener { | 
| 46 |  | - | 
| 47 | 48 |     private static volatile boolean stateChanged = false; | 
| 48 | 49 |     private static volatile boolean focusGained = false; | 
| 49 | 50 |     private static JTextField txtField; | 
| @@ -71,51 +72,39 @@ public static void main(String[] args) throws Exception { | 
| 71 | 72 |             Robot robot = new Robot(); | 
| 72 | 73 |             robot.setAutoDelay(50); | 
| 73 | 74 | 
 | 
| 74 |  | -            SwingUtilities.invokeAndWait(new Runnable() { | 
| 75 |  | - | 
| 76 |  | -                public void run() { | 
| 77 |  | -                    createAndShowGUI(); | 
| 78 |  | -                } | 
| 79 |  | -            }); | 
| 80 |  | - | 
|  | 75 | +            SwingUtilities.invokeAndWait(() -> createAndShowGUI()); | 
| 81 | 76 |             robot.waitForIdle(); | 
| 82 |  | - | 
| 83 |  | -            SwingUtilities.invokeAndWait(new Runnable() { | 
| 84 |  | - | 
| 85 |  | -                public void run() { | 
| 86 |  | -                    txtField.requestFocus(); | 
| 87 |  | -                } | 
| 88 |  | -            }); | 
| 89 |  | - | 
|  | 77 | +            SwingUtilities.invokeAndWait(() -> txtField.requestFocus()); | 
| 90 | 78 |             robot.waitForIdle(); | 
| 91 | 79 | 
 | 
| 92 | 80 |             if (!focusGained) { | 
| 93 | 81 |                 throw new RuntimeException("Couldn't gain focus for text field"); | 
| 94 | 82 |             } | 
| 95 | 83 | 
 | 
| 96 |  | -            SwingUtilities.invokeAndWait(new Runnable() { | 
| 97 |  | - | 
| 98 |  | -                public void run() { | 
| 99 |  | -                    tab.addChangeListener((ChangeListener) listener); | 
| 100 |  | -                    txtField.removeFocusListener((FocusListener) listener); | 
| 101 |  | -                } | 
|  | 84 | +            SwingUtilities.invokeAndWait(() -> { | 
|  | 85 | +                tab.addChangeListener((ChangeListener) listener); | 
|  | 86 | +                txtField.removeFocusListener((FocusListener) listener); | 
| 102 | 87 |             }); | 
| 103 | 88 | 
 | 
| 104 | 89 |             robot.waitForIdle(); | 
| 105 | 90 | 
 | 
| 106 |  | -            if (Platform.isOSX()) { | 
| 107 |  | -                Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_B); | 
| 108 |  | -            } else { | 
| 109 |  | -                Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_B); | 
| 110 |  | -            } | 
|  | 91 | +            robot.keyPress(KeyEvent.VK_ALT); | 
|  | 92 | +            robot.keyPress(KeyEvent.VK_B); | 
|  | 93 | +            robot.keyRelease(KeyEvent.VK_B); | 
|  | 94 | +            robot.keyRelease(KeyEvent.VK_ALT); | 
| 111 | 95 | 
 | 
| 112 | 96 |             robot.waitForIdle(); | 
| 113 | 97 | 
 | 
| 114 | 98 |             if (!stateChanged || tab.getSelectedIndex() != 1) { | 
| 115 |  | -                throw new RuntimeException("JTabbedPane mnemonics don't work from outside the tabbed pane"); | 
|  | 99 | +                throw new RuntimeException("JTabbedPane mnemonics don't " + | 
|  | 100 | +                        "work from outside the tabbed pane"); | 
| 116 | 101 |             } | 
| 117 | 102 |         } finally { | 
| 118 |  | -            if (frame != null) SwingUtilities.invokeAndWait(() ->  frame.dispose()); | 
|  | 103 | +            SwingUtilities.invokeAndWait(() -> { | 
|  | 104 | +                if (frame != null) { | 
|  | 105 | +                    frame.dispose(); | 
|  | 106 | +                } | 
|  | 107 | +            }); | 
| 119 | 108 |         } | 
| 120 | 109 |     } | 
| 121 | 110 | 
 | 
|  | 
0 commit comments