java - How to deselect an item in a jList after a certain ammount of milliseconds on a mouseExit event -
i have jlist called todolist
when user click on item in list, stays selected. selected item in list deselect "by itself" after 400 milliseconds when mouse exits jlist.
this must run if there selected in list.
i using netbeans ide , have tried far:
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); } } }
and
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); } } }
these both make stop working.
my though process need create new thread wait 400 milliseconds , run clearselection() method of jlist. happen every time mouse exits list , run if there in list selected.
i hope explaining problem thoroughly enough.
the problem object#wait
waiting(rather sleeping) notified not happening. instead timeout causing interruptedexception
bypassing call clearselection
.
don't use raw threads
in swing
applications. instead use swing timer
designed interact swing components.
if (!todolist.isselectionempty()) { timer timer = new timer(400, new actionlistener() { public void actionperformed(actionevent evt) { todolist.clearselection(); } }); timer.setrepeats(false); timer.start(); }
Comments
Post a Comment