Example usage for javax.swing JPanel setFocusCycleRoot

List of usage examples for javax.swing JPanel setFocusCycleRoot

Introduction

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

Prototype

public void setFocusCycleRoot(boolean focusCycleRoot) 

Source Link

Document

Sets whether this Container is the root of a focus traversal cycle.

Usage

From source file:FocusCycleSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Focus Cycle Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridLayout(3, 3));
    for (int i = 0; i < 3; i++) {
        JButton button = new JButton("" + i);
        frame.add(button);//w  ww  .  j  a  v a2 s .c  om
    }
    JPanel panel = new JPanel();
    panel.setFocusCycleRoot(true);
    panel.setFocusTraversalPolicyProvider(true);
    panel.setLayout(new GridLayout(1, 3));
    for (int i = 0; i < 3; i++) {
        JButton button = new JButton("" + (i + 3));
        panel.add(button);
    }
    frame.add(panel);
    for (int i = 0; i < 3; i++) {
        JButton button = new JButton("" + (i + 6));
        frame.add(button);
    }
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

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

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

    for (int i = 0; i < 3; i++) {
        JButton button = new JButton("" + i);
        frame.add(button);//from   w  ww.  j a  v  a 2s  .com
    }

    JPanel panel = new JPanel();
    panel.setFocusCycleRoot(true);
    panel.setFocusTraversalPolicyProvider(true);
    panel.setLayout(new GridLayout(1, 3));
    for (int i = 0; i < 3; i++) {
        JButton button = new JButton("" + (i + 3));
        panel.add(button);
    }
    frame.add(panel);

    for (int i = 0; i < 3; i++) {
        JButton button = new JButton("" + (i + 6));
        frame.add(button);
    }

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