Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Changing the color of a Jbutton

843805Dec 4 2006 — edited Dec 6 2006
I am trying to change the color of a Jbutton depending on values in an array. This method reads an array and try to changes the color of a button depending on the value in the aray. My problem is that that setForeground() does not seem to be working. Just for kicks I tried setText() and it works fine. I am running this method is a seprate thread so the GUI is not locking up.
 


public void playSequance()
{
int[] tempArray = new int[100];
tempArray = test.sequance();

  for(int i=0; i<tempArray.length; i++)
  {

    if (tempArray[i] == 1)
	{
	  System.out.println("a red button was detected");
	  greenButton.setText("some text is on the button now");//this works	
      
      // trying to change the color here from red to white. this does not work.
	  redButton.setForeground(Color.white);
			
	  //test.redSound();//play a beep, got anoying after several 100 tests, so commented out
			
	  try{Thread.sleep(500);}catch(InterruptedException E) {}//pause in between beeps
   }

   if (tempArray[i] == 2)
   {
		//same code here but for a different button
			
   }


}

}//end playsequance()
any ideas?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 3 2007
Added on Dec 4 2006
4 comments
423 views