JTable:更改遍历顺序

时间:2011-06-19 08:04:08

标签: java swing jtable traversal

按Enter键时,我希望水平遍历JTable。我试过JTable.changeSelection,但它似乎没有用。任何想法如何改变遍历行为?

3 个答案:

答案 0 :(得分:3)

输入是垂直遍历,TAB是水平的,只需按住Enter事件并为Tab事件生成Tab事件或调用函数。但是你应该设置下一个属性:

            table.setSelectionMode(
                    ListSelectionModel.SINGLE_SELECTION);

答案 1 :(得分:3)

阅读Key Bindings。您可能希望“与不同的KeyStroke共享动作

答案 2 :(得分:1)

JTable.getInputMap(JInternalFrame.WHEN_ANCESTOR_OF _FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "SOME_ACTION");
JTable.getInputMap(JInternalFrame.WHEN_FOCUSED)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "SOME_ACTION");

JTable.getActionMap().put("SOME_ACTION", actions);


actions = new AbstractAction() {

public void actionPerformed(ActionEvent ae) {
//This action will get fired on Enter Key
}
};