• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JButton background color in different "Look and Feel"  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using this simple code snippet:

I get the correct color, when using the default "Metal" Look and Feel:



But I get no color with "Nimbus":



And no color with "Windows" as well:



Any idea why this happens and how can I fix it?

Thank you in advance!
 
Marshal
Posts: 5988
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your images aren't viewable, probably because they point to a web page and not a true image.  You can attach images to your post if you can't find your image on the web.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Default behavior for Swing components, like JButton is to use its UI delegate to paint the component. The UI delegate is determined by the look-and-feel. The look-and-feel may ignore calls to method setBackground(). Hence if you want to change the background color you need to either adjust the look-and-feel or override the painting code used by class JButton.

As you can see, the Metal look-and-feel honors calls to method setBackground() whereas Nimbus does not.
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!