< prev index next >

test/javax/swing/JRadioButton/8033699/bug8033699.java

Print this page

        

*** 24,59 **** /* * @test * @key headful * @library ../../regtesthelpers * @build Util ! * @bug 8033699 8154043 * @summary Incorrect radio button behavior when pressing tab key - * @author Vivi An * @run main bug8033699 */ ! ! import javax.swing.*; ! import javax.swing.event.*; ! import java.awt.event.*; ! import java.awt.*; public class bug8033699 { - private static Robot robot; private static JButton btnStart; - private static ButtonGroup btnGrp; private static JButton btnEnd; private static JButton btnMiddle; private static JRadioButton radioBtn1; private static JRadioButton radioBtn2; private static JRadioButton radioBtn3; private static JRadioButton radioBtnSingle; public static void main(String args[]) throws Throwable { SwingUtilities.invokeAndWait(new Runnable() { public void run() { createAndShowGUI(); } }); robot = new Robot(); --- 24,70 ---- /* * @test * @key headful * @library ../../regtesthelpers * @build Util ! * @bug 8033699 8154043 8167160 * @summary Incorrect radio button behavior when pressing tab key * @run main bug8033699 */ ! import java.awt.KeyboardFocusManager; ! import java.awt.Robot; ! import java.awt.event.KeyEvent; ! import java.util.logging.Level; ! import java.util.logging.Logger; ! import javax.swing.BorderFactory; ! import javax.swing.BoxLayout; ! import javax.swing.ButtonGroup; ! import javax.swing.JButton; ! import javax.swing.JFrame; ! import javax.swing.JPanel; ! import javax.swing.JRadioButton; ! import javax.swing.SwingUtilities; ! import javax.swing.UIManager; ! import javax.swing.UnsupportedLookAndFeelException; public class bug8033699 { + private static JFrame mainFrame; + private static Robot robot; private static JButton btnStart; private static JButton btnEnd; private static JButton btnMiddle; private static JRadioButton radioBtn1; private static JRadioButton radioBtn2; private static JRadioButton radioBtn3; private static JRadioButton radioBtnSingle; public static void main(String args[]) throws Throwable { SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { + changeLAF(); createAndShowGUI(); } }); robot = new Robot();
*** 82,96 **** // tab to radio button in group from component in the middle of button group layout runTest7(); // down key circle back to first button in grouped radio button runTest8(); } ! private static void createAndShowGUI() { ! JFrame mainFrame = new JFrame("Bug 8033699 - 8 Tests for Grouped/Non Group Radio Buttons"); btnStart = new JButton("Start"); btnEnd = new JButton("End"); btnMiddle = new JButton("Middle"); JPanel box = new JPanel(); --- 93,129 ---- // tab to radio button in group from component in the middle of button group layout runTest7(); // down key circle back to first button in grouped radio button runTest8(); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + mainFrame.dispose(); + } + }); } ! private static void changeLAF() { ! String currentLAF = UIManager.getLookAndFeel().toString(); ! System.out.println(currentLAF); ! currentLAF = currentLAF.toLowerCase(); ! if (currentLAF.contains("aqua") || currentLAF.contains("nimbus")) { ! try { ! UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); ! } catch (ClassNotFoundException ! | InstantiationException ! | IllegalAccessException ! | UnsupportedLookAndFeelException ex) { ! Logger.getLogger(bug8033699.class.getName()).log(Level.SEVERE, null, ex); ! } ! } ! } + private static void createAndShowGUI() { + mainFrame = new JFrame("Bug 8033699 - 8 Tests for Grouped/Non Group Radio Buttons"); btnStart = new JButton("Start"); btnEnd = new JButton("End"); btnMiddle = new JButton("Middle"); JPanel box = new JPanel();
*** 130,237 **** mainFrame.setVisible(true); mainFrame.toFront(); } // Radio button Group as a single component when traversing through tab key ! private static void runTest1() throws Exception{ hitKey(robot, KeyEvent.VK_TAB); hitKey(robot, KeyEvent.VK_TAB); hitKey(robot, KeyEvent.VK_TAB); SwingUtilities.invokeAndWait(new Runnable() { public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtnSingle) { System.out.println("Radio Button Group Go To Next Component through Tab Key failed"); throw new RuntimeException("Focus is not on Radio Button Single as Expected"); } } }); } // Non-Grouped Radio button as a single component when traversing through tab key ! private static void runTest2() throws Exception{ hitKey(robot, KeyEvent.VK_TAB); SwingUtilities.invokeAndWait(new Runnable() { public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != btnEnd) { System.out.println("Non Grouped Radio Button Go To Next Component through Tab Key failed"); throw new RuntimeException("Focus is not on Button End as Expected"); } } }); } // Non-Grouped Radio button and Group Radio button as a single component when traversing through shift-tab key ! private static void runTest3() throws Exception{ hitKey(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB); hitKey(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB); hitKey(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB); SwingUtilities.invokeAndWait(new Runnable() { public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtn1) { System.out.println("Radio button Group/Non Grouped Radio Button SHIFT-Tab Key Test failed"); throw new RuntimeException("Focus is not on Radio Button A as Expected"); } } }); } // Using arrow key to move focus in radio button group ! private static void runTest4() throws Exception{ hitKey(robot, KeyEvent.VK_DOWN); hitKey(robot, KeyEvent.VK_RIGHT); SwingUtilities.invokeAndWait(new Runnable() { public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtn3) { System.out.println("Radio button Group UP/LEFT Arrow Key Move Focus Failed"); throw new RuntimeException("Focus is not on Radio Button C as Expected"); } } }); } ! private static void runTest5() throws Exception{ hitKey(robot, KeyEvent.VK_UP); hitKey(robot, KeyEvent.VK_LEFT); SwingUtilities.invokeAndWait(new Runnable() { public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtn1) { System.out.println("Radio button Group Left/Up Arrow Key Move Focus Failed"); throw new RuntimeException("Focus is not on Radio Button A as Expected"); } } }); } ! private static void runTest6() throws Exception{ hitKey(robot, KeyEvent.VK_UP); hitKey(robot, KeyEvent.VK_UP); SwingUtilities.invokeAndWait(new Runnable() { public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtn2) { System.out.println("Radio button Group Circle Back To First Button Test"); throw new RuntimeException("Focus is not on Radio Button B as Expected"); } } }); } ! private static void runTest7() throws Exception{ hitKey(robot, KeyEvent.VK_TAB); SwingUtilities.invokeAndWait(new Runnable() { public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != btnMiddle) { System.out.println("Separate Component added in button group layout"); throw new RuntimeException("Focus is not on Middle Button as Expected"); } } }); } ! private static void runTest8() throws Exception{ hitKey(robot, KeyEvent.VK_TAB); SwingUtilities.invokeAndWait(new Runnable() { public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtnSingle) { System.out.println("Separate Component added in button group layout"); throw new RuntimeException("Focus is not on Radio Button Single as Expected"); } --- 163,278 ---- mainFrame.setVisible(true); mainFrame.toFront(); } // Radio button Group as a single component when traversing through tab key ! private static void runTest1() throws Exception { hitKey(robot, KeyEvent.VK_TAB); hitKey(robot, KeyEvent.VK_TAB); hitKey(robot, KeyEvent.VK_TAB); SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtnSingle) { System.out.println("Radio Button Group Go To Next Component through Tab Key failed"); throw new RuntimeException("Focus is not on Radio Button Single as Expected"); } } }); } // Non-Grouped Radio button as a single component when traversing through tab key ! private static void runTest2() throws Exception { hitKey(robot, KeyEvent.VK_TAB); SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != btnEnd) { System.out.println("Non Grouped Radio Button Go To Next Component through Tab Key failed"); throw new RuntimeException("Focus is not on Button End as Expected"); } } }); } // Non-Grouped Radio button and Group Radio button as a single component when traversing through shift-tab key ! private static void runTest3() throws Exception { hitKey(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB); hitKey(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB); hitKey(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB); SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtn1) { System.out.println("Radio button Group/Non Grouped Radio Button SHIFT-Tab Key Test failed"); throw new RuntimeException("Focus is not on Radio Button A as Expected"); } } }); } // Using arrow key to move focus in radio button group ! private static void runTest4() throws Exception { hitKey(robot, KeyEvent.VK_DOWN); hitKey(robot, KeyEvent.VK_RIGHT); SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtn3) { System.out.println("Radio button Group UP/LEFT Arrow Key Move Focus Failed"); throw new RuntimeException("Focus is not on Radio Button C as Expected"); } } }); } ! private static void runTest5() throws Exception { hitKey(robot, KeyEvent.VK_UP); hitKey(robot, KeyEvent.VK_LEFT); SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtn1) { System.out.println("Radio button Group Left/Up Arrow Key Move Focus Failed"); throw new RuntimeException("Focus is not on Radio Button A as Expected"); } } }); } ! private static void runTest6() throws Exception { hitKey(robot, KeyEvent.VK_UP); hitKey(robot, KeyEvent.VK_UP); SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtn2) { System.out.println("Radio button Group Circle Back To First Button Test"); throw new RuntimeException("Focus is not on Radio Button B as Expected"); } } }); } ! private static void runTest7() throws Exception { hitKey(robot, KeyEvent.VK_TAB); SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != btnMiddle) { System.out.println("Separate Component added in button group layout"); throw new RuntimeException("Focus is not on Middle Button as Expected"); } } }); } ! private static void runTest8() throws Exception { hitKey(robot, KeyEvent.VK_TAB); SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtnSingle) { System.out.println("Separate Component added in button group layout"); throw new RuntimeException("Focus is not on Radio Button Single as Expected"); }
< prev index next >