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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -