Example usage for javax.swing JFrame setFocusTraversalPolicy

List of usage examples for javax.swing JFrame setFocusTraversalPolicy

Introduction

In this page you can find the example usage for javax.swing JFrame setFocusTraversalPolicy.

Prototype

public void setFocusTraversalPolicy(FocusTraversalPolicy policy) 

Source Link

Document

Sets the focus traversal policy that will manage keyboard traversal of this Container's children, if this Container is a focus cycle root.

Usage

From source file:FocusTraversalExample.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setFocusTraversalPolicy(new AlphaButtonPolicy());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new FocusTraversalExample());
    frame.setSize(400, 300);/*from  w ww.  j  ava 2  s. c om*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setFocusTraversalPolicy(new AlphaButtonPolicy());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new Main());
    frame.setSize(400, 300);/*w  w  w. j  a v  a 2  s .c  o m*/
    frame.setVisible(true);
}

From source file:FocusTraversalExample.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Alphabetized Button Focus Traversal");
    frame.setFocusTraversalPolicy(new AlphaButtonPolicy());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new FocusTraversalExample());
    frame.setSize(400, 300);/*from  w w  w  .jav  a  2  s  .  c  o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Reverse Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridLayout(3, 3));
    for (int i = 0; i < 9; i++) {
        JButton button = new JButton(Integer.toString(i));
        frame.add(button);/*from  w ww . j  a v a2 s . co  m*/
    }
    final Container contentPane = frame.getContentPane();
    Comparator<Component> comp = new Comparator<Component>() {
        public int compare(Component c1, Component c2) {
            Component comps[] = contentPane.getComponents();
            List list = Arrays.asList(comps);
            int first = list.indexOf(c1);
            int second = list.indexOf(c2);
            return second - first;
        }
    };
    FocusTraversalPolicy policy = new SortingFocusTraversalPolicy(comp);
    frame.setFocusTraversalPolicy(policy);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Reverse Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setLayout(new GridLayout(3, 3));

    for (int i = 9; i > 0; i--) {
        JButton button = new JButton(Integer.toString(i));
        frame.add(button, 0);//from   ww  w .  java 2 s  .  c  om
    }

    final Container contentPane = frame.getContentPane();
    Comparator<Component> comp = new Comparator<Component>() {
        public int compare(Component c1, Component c2) {
            Component comps[] = contentPane.getComponents();
            List list = Arrays.asList(comps);
            int first = list.indexOf(c1);
            int second = list.indexOf(c2);
            return second - first;
        }
    };

    FocusTraversalPolicy policy = new SortingFocusTraversalPolicy(comp);
    frame.setFocusTraversalPolicy(policy);

    frame.setSize(300, 200);
    frame.setVisible(true);
}