• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

JButton background color in different "Look and Feel"

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic