import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FocusCycleSample {
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);
}
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);
}
}
|