Example usage for javax.swing JPanel getFocusTraversalKeys

List of usage examples for javax.swing JPanel getFocusTraversalKeys

Introduction

In this page you can find the example usage for javax.swing JPanel getFocusTraversalKeys.

Prototype

public Set<AWTKeyStroke> getFocusTraversalKeys(int id) 

Source Link

Document

Returns the Set of focus traversal keys for a given traversal operation for this Container.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Border Layout");
    aWindow.setBounds(30, 30, 300, 300);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();

    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));

    Set<AWTKeyStroke> set = p.getFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
    //set = new HashSet(set);
    KeyStroke up = KeyStroke.getKeyStroke("A");
    set.add(up);/* ww  w  . j  a  v a2 s.  co  m*/
    System.out.println(set);
    p.setFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, set);
    aWindow.add(p);
    aWindow.setVisible(true);
}

From source file:KeyboardFocusManagerDemo.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Border Layout");
    aWindow.setBounds(30, 30, 300, 300); // Size
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();

    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));

    Set<AWTKeyStroke> set = p.getFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
    set = new HashSet(set);
    KeyStroke up = KeyStroke.getKeyStroke("A");
    set.add(up);/* w ww  .  j a  v  a2 s .  c  o m*/
    System.out.println(set);

    p.setFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, set);

    aWindow.add(p);

    aWindow.setVisible(true); // Display the window
}