开发者

JTable: change traversal order

I want to traverse horizontally through a JTable, when pressing enter. I've tried with JTable.changeSelection but it doesnt seem t开发者_StackOverflow社区o work. Any ideas how to change the traversal behavior?


Read up on Key Bindings. You would want to "share an Action with a different KeyStroke"


Enter is vertical traverse , TAB is horisontal, just hold Enter event and generate Tab event or call function for Tab Event. But you should set up next properties:

            table.setSelectionMode(
                    ListSelectionModel.SINGLE_SELECTION);


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
}
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜