【发布时间】:2010-06-18 04:14:40
【问题描述】:
我发现 this forum thread 建议覆盖 ListSelectionModel 以防止行被选中。
当当前所选项目存在未保存的更改(表外部)时,我想防止选择更改,直到用户确认丢弃。比如:
public class confirmSelectionChange extends DefaultListSelectionModel {
public void setSelectionInterval(int index0, int index1) {
if (unsavedChanges()) {
super.setSelectionInterval(int index0, int index1);
}
}
private boolean unsavedChanges() {
if (noUnsavedChangesExist) {
return true;
}
// Present modal dialog: save, discard cancel
if (dialogAnswer == SAVE) {
// save changes
return true;
} else if (dialogAnswer == DISCARD) {
return true;
} else {
return false;
}
}
}
是否可以在 ListSelectionModel 更改中间插入阻塞代码?有没有更好的方法来拦截选择更改事件?
我已经在听他们的了,但到那时变化已经发生了。
【问题讨论】:
标签: java user-interface swing jtable selection