Timer Issue in Java - Time not Stopping when setRepeat(false) is set -
i'm hoping me fix issue i'm having timers. when timer.start() run, timer starts. however, seems repeat endlessly.
i need timer execute once. how can achieve if timer.setrepeats(false) not working?
actionlistener updatepane = new actionlistener() { public void actionperformed(actionevent ae) { try { msgpanedoc.insertstring(msgpanedoc.getlength(), "click", msgpanedoc.getstyle("bold_style")); } catch (badlocationexception ex) { }}}; timer timer = new timer(3000,updatepane); timer.start(); timer.setrepeats(false);
you have call inside the event dispatch thread.
try swingutilities.invokelater() or eventqueue.invokelater()
sample code:
swingutilities.invokelater(new runnable() { @override public void run() { actionlistener actionlistener = new actionlistener() { public void actionperformed(actionevent ae) { system.out.println("hello"); } }; timer timer = new timer(1000, actionlistener); timer.start(); timer.setrepeats(false); } });
Comments
Post a Comment