【发布时间】:2013-03-31 01:47:32
【问题描述】:
我有一个名为todoList的jList
当用户单击列表中的某个项目时,它会保持选中状态。但是我希望列表中当前选定的项目在鼠标退出 jList 时在 400 毫秒后“自行”取消选择。
只有在列表中已经选择了某些内容时才能运行。
我正在使用 Netbeans IDE,这是迄今为止尝试过的:
private void todoListMouseExited(java.awt.event.MouseEvent evt) {
if (!todoList.isSelectionEmpty()) {
Thread thread = new Thread();
try {
thread.wait(400L);
todoList.clearSelection();
} catch (InterruptedException ex) {
System.out.println(ex);
}
}
}
和
private void todoListMouseExited(java.awt.event.MouseEvent evt) {
if (!todoList.isSelectionEmpty()) {
Thread thread= Thread.currentThread();
try {
thread.wait(400L);
todoList.clearSelection();
} catch (InterruptedException ex) {
System.out.println(ex);
}
}
}
这些都只是让一切都停止工作。
我的过程是我需要创建一个等待 400 毫秒的新线程,然后运行 jList 的 clearSelection() 方法。每次鼠标退出列表时都会发生这种情况,并且仅当列表中有已被选中的内容时才会运行。
我希望我能彻底解释我的问题。
【问题讨论】:
标签: java swing timer jlist listselectionlistener