• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

how to flash JButton background

 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic