当前,我有一个JList监听列表选择监听器。在选择之前验证JList出现
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {
// When the user release the mouse button and completes the selection,
// getValueIsAdjusting() becomes false
if (evt.getValueIsAdjusting()) {
/*
In certain situation, I may want to prevent user from selecting other
than current selection. How can I do so?
*/
}
}
在某些情况下,我可能想阻止用户选择除当前选择以外的选项。我该怎么做?
当我收到ListSelectionEvent时,似乎太晚了。但是,如果我想在ListSelectionEvent发生之前这样做,我不知道该用户正在尝试选择其他。
这里是塞纳里奥之一。
JList包含项目名称列表。 因此,每当用户选择新的列表项目时,我们需要从当前项目中打开视图,并显示新项目。 但是,当前的项目可能尚未储存。 因此,如果当前项目尚未保存,我们会要求用户确认“保存项目?” (是,否,取消) 当用户选择取消时,这意味着他想取消他的“选择到另一个项目”动作。他想坚持当前的JList选择。 我们将弹出jList1ValueChanged事件句柄中的确认对话框。 但是,当我们试图坚持当前的JList选择时,已经太晚了。
得到你!由于时间不够,我正在使用类似的实现方式。 – 2009-10-28 03:44:54