Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to flash JButton background

 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
raj madhuram
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't be doing that stuff in the event dispatching thread. The following should work.

regards,
Raj
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic