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!

JButton setBackground() has no effect

843806Feb 5 2009 — edited Feb 5 2009
Hello,
I'm currently working on a small Mastermind game where the user has to guess the colors which the computer is thinking of. To do this they will have to press a number of buttons which then change colors until they are satisfied.
Here's my problem: I want to use JButtons with the setBackground() method but it doesn't work. After some searching I found the setOpaque method but it didn't help me at all (no effect). I even tried setOpaque on the JPanel which the button is placed on.
Here's my current code:
for (int i = 0; i<numberOfPegs; i++) {
	buttons[i] = new JButton();
	buttons.setOpaque(true);
buttons[i].setBackground(Color.GREEN);
buttons[i].setBounds(new Rectangle(12+(pegSize+5)*i+10, (pegSize+6)*(numberOfTries+1), pegSize, pegSize));
gamePanel.add(buttons[i]);
}

I use 1.6 with Eclipse on Mac OS X 10.5.6. Any help would be greatly appreciated.

Edited by: pg-robban on Feb 5, 2009 3:40 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 5 2009
Added on Feb 5 2009
6 comments
1,873 views