gpt4 book ai didi

java - JTable - 在列末尾点击返回后不应移动到下一列

转载 作者:行者123 更新时间:2023-11-29 03:53:17 25 4
gpt4 key购买 nike

JTable 中的默认行为似乎是,如果我到达一列的最后一行并按回车键,我将转到下一列的第一行。有没有办法避免这种情况?请建议我可以留在同一列的最后一行的方法。我还想避免这样一种情况,即我被带到下一栏,然后检测到它并返回到前一栏,因为我有一些与之关联的听众。感谢您的帮助。

最佳答案

要更改任何导航行为,请将默认导航操作替换为您自己的。最好通过包装默认值:有条件地执行默认值或自定义内容。有点像

    Object key = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.get(KeyStroke.getKeyStroke("ENTER"));
final Action action = table.getActionMap().get(key);
Action custom = new AbstractAction("wrap") {

@Override
public void actionPerformed(ActionEvent e) {
int row = table.getSelectionModel().getLeadSelectionIndex();
if (row == table.getRowCount() - 1) {
// do custom stuff
// return if default shouldn't happen or call default after
return;
}
action.actionPerformed(e);
}

};
table.getActionMap().put(key, custom);

关于java - JTable - 在列末尾点击返回后不应移动到下一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7741493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com