File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton color" Watch "JButton color" New topic

JButton color

John Zelek

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");
Russell Slighton

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)
It is sorta covered in the JavaRanch Style Guide.
subject: JButton color
It's not a secret anymore!