Java - 更改行为Tab键

时间:2014-09-22 14:57:00

标签: java tabs focus

我有简单的gui app,当我按Tab键时,它会像这样移动焦点:

img http://oi59.tinypic.com/2ica3ch.jpg

但我想这样移动:

img http://oi62.tinypic.com/ndssr7.jpg

public class Test extends javax.swing.JFrame {

    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;   

    public Test() {
        initComponents();
    }

    // NetBeans generate Form code

    public static void main(String args[]) {
        new Test().setVisible(true);
    }

}

1 个答案:

答案 0 :(得分:1)

您需要自定义FocusTraversalPolicy。在这里看一个例子 - > Example