AWT/Swing控件的tab顺如何设定
如题,求教AWT/Swing控件的tab顺如何设定, 如buttun,lbl,checkbox...jtable如何设定它们的tab顺序..
------最佳解决方案--------------------Swing中设置按Tab键后焦点的顺序
转贴
Java代码
1.import javax.swing.*;
2.import java.awt.*;
3.import java.util.Arrays;
4.import java.util.ArrayList;/**
5. * <p>Title: </p>
6. *
7. * <p>Description: </p>
8. *
9. * <p>Copyright: Copyright (c) 2008</p>
10. *
11. * <p>Company: </p>
12. *
13. * @author not attributable
14. * @version 1.0
15. */
16.public class BorderFocus {
17. public static void main(String args[]) {
18. JFrame frame = new JFrame("Focus Cycling");
19. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20. Container contentPane = frame.getContentPane();
21. JButton north = new JButton("North");
22. contentPane.add(north, BorderLayout.NORTH);
23. JButton south = new JButton("South");
24. contentPane.add(south, BorderLayout.SOUTH);
25. JButton east = new JButton("East");
26. contentPane.add(east, BorderLayout.EAST);
27. JButton west = new JButton("West");
28. contentPane.add(west, BorderLayout.WEST);
29. JButton center = new JButton("Center");
30. contentPane.add(center, BorderLayout.CENTER);
31. contentPane.setFocusable(false);
32. ArrayList<Component> list = new ArrayList<Component>();
33.
34. list.add(north);
35. list.add(east);
36. list.add(south);
37. list.add(west);
38. list.add(center);
39. final ArrayList comList = list;
40. FocusTraversalPolicy policy = new FocusTraversalPolicy() {
41. public Component getFirstComponent(Container focusCycleRoot) {
42. return (Component)comList.get(0);
43. }
44. public Component getLastComponent(Container focusCycleRoot) {
45. return (Component) comList.get(comList.size()-1);