File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JButton color Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton color" Watch "JButton color" New topic
Author

JButton color

John Zelek
Greenhorn

Joined: Nov 10, 2012
Posts: 2
I am trying to set up an interface with nine buttons, each with a different color. How do I set/change the color of each of the buttons. I am not trying to change the text color on the button. I am trying to change the color of the button itself. Seems like a simple task but not finding anything. I am trying to mimic the game Simon Says and I would like each button to be a different color, not just the border

JButton b1 = new JButton("1");
//b1.setForeground(Color.RED);
//b1.setBackground(Color.RED);
gamePanel.add(b1);
Russell Slighton
Greenhorn

Joined: Nov 18, 2012
Posts: 5
You could try to add a border then setBackgroundColor(), however, after adding a border, the button will not darken when clicked and will also looses several graphical functions. (But not functional functions)
 
jQuery in Action, 2nd edition
 
subject: JButton color