aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Can I change Swing Timer delay inside the action listener? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can I change Swing Timer delay inside the action listener?" Watch "Can I change Swing Timer delay inside the action listener?" New topic
Author

Can I change Swing Timer delay inside the action listener?

Stavros Kanarakis
Greenhorn

Joined: Sep 28, 2010
Posts: 12
Hi all,

I have an application in which a Swing timer is started with repeats(false). This is not shown in the code.
Inside that timer actionlistener, and depending on the logic, I want to stop this timer, set another delay value and restart it.

Everything works fine except for the new delay. The timer gets restarted for one time again, but it keeps getting the delay value that was given at the first time of its run. It gets always "someValue" and not "newValue".

Do you know why?

Thanks
Steve



Exploring Java world...
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2183
    
    7
I would guess that you don't invoke the start() method again because start() tells the Timer to use the initialDelay, which you haven't reset.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4546
    
    5

Stavros Kanarakis wrote:

Uh-oh, that doesn't look good at all. The actionPerformed method is invoked on the EDT, and it rather looks like you might freeze the GUI with all that 'unrelated code' and the implied file I/O


luck, db
There are no new questions, but there may be new answers.
 
Don't get me started about those stupid light bulbs.
 
subject: Can I change Swing Timer delay inside the action listener?