我发现这个论坛帖子建议覆盖 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否可以在 ListSelectionModel 更改的中间插入阻塞代码?有没有更好的方法来拦截选择更改事件?
我已经在倾听他们的声音,但那时已经发生了变化。