aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes how to flash JButton background Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to flash JButton background" Watch "how to flash JButton background" New topic
Author

how to flash JButton background

Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

ok... I'm building a game where the player selects three cards (JButtons) that make a "set" -- if they are incorrect, I want to flash the background of the button to RED, then back to the normal (light gray) color and game play can continue.
Problem is -- I make calls to setBackground() but the button is not repainted... I've tried calling .validate() but it doesn't help... any ideas?
I've created a small version of what I'm doing below:

[ April 03, 2003: Message edited by: Jessica Sant ]

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
raj madhuram
Ranch Hand

Joined: Oct 10, 2001
Posts: 71
You shouldn't be doing that stuff in the event dispatching thread. The following should work.

regards,
Raj
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

oooo -- isn't it fun when you can answer your own question (kinda) Is this the best solution??
using a javax.swing.Timer Object -->
raj madhuram
Ranch Hand

Joined: Oct 10, 2001
Posts: 71
Hi,
That should work because you have moved it out of the event dispatching thread. However, controlling # of blinks (if that is important) is a bit hacky. My version below:

regards,
Raj
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to flash JButton background