Java Code Examples for javax.swing.JCheckBox#isFocusOwner()

The following examples show how to use javax.swing.JCheckBox#isFocusOwner() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WrongKeyTypedConsumedTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 2
Source File: WrongKeyTypedConsumedTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 3
Source File: WrongKeyTypedConsumedTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 4
Source File: WrongKeyTypedConsumedTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 5
Source File: WrongKeyTypedConsumedTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 6
Source File: WrongKeyTypedConsumedTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 7
Source File: WrongKeyTypedConsumedTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 8
Source File: WrongKeyTypedConsumedTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 9
Source File: WrongKeyTypedConsumedTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 10
Source File: WrongKeyTypedConsumedTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 11
Source File: WrongKeyTypedConsumedTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 12
Source File: WrongKeyTypedConsumedTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
Example 13
Source File: WrongKeyTypedConsumedTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}