This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 2152
    
    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: 4523
    
    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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can I change Swing Timer delay inside the action listener?
 
Similar Threads
Gui animation
listening for events in other windows
How to select text in a Custom JSpinner
some qns...help appreciated
mouse clicks using timer