Changing JButton background colour temporarily?
Posted
by sashep
on Stack Overflow
See other posts from Stack Overflow
or by sashep
Published on 2010-03-17T18:35:35Z
Indexed on
2010/03/17
18:41 UTC
Read the original article
Hit count: 459
Hi, I'm super new to Java, and in need of some help. I'm making a little java desktop application where I basically have a grid of 4 JButtons ( 2 x 2 grid), and I need the background colour of individual JButtons to change, and after one second, change back to the original colour (the game I'm trying to make is like Simon, where you have to follow a pattern of buttons that light up). I have a vector that contains randomly generated numbers in the range of 1 to 4, and I want to be able to get each element from the vector and get the corresponding button to change to a different colour for one second (for example, if the vector contains 2 4 1, I would want button 2 to change, then button 4 to change, then button 1 to change).
Is this possible or is there a better way to go about doing this with something other than JButtons? How do I implement this?
Also, I'm running Mac OS X, which apparently (based on some things I've read on forums) doesn't like JButtons background changing (I think it's because of system look and feel), how can I change this so it works on mac?
Thank you in advance for any help :)
© Stack Overflow or respective owner