Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButton background color

 
Mindy Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,
How can i clear the background color of a JButton which current background is blue?
What is the RGB color code for the default button color?
Thanks
 
Carlos Failde
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Pardner. You could use getBackground to store the colour of the button before you change it to blue, then use setBackground(storedColor). I thought that there might have been a constant defined somewhere in the swing package for the default colour but I could not find one.
 
Mindy Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help!
Also, i found the default background color is R=204, G=204, B=204.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the background color could change based on the Look and Feel. You can use UIManager.getColor( "Button.background" ) to get the default background color of buttons in the current Look and Feel.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic