• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to change the background color of a Dialog?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This one is really tricky.

If I generate a dialog from JOptionPane, can I change the background color of this dialog? I wonder whether this should be done on the JOptionPane or on the dialog after it is generated. Have tried but didn't get the expected result.

What's even more tricky is, I wonder if it is possible to change the color of the buttons on that dialog -- I mean the default button "OK" or any customized buttons. Since we get the button for free, how can we even get a reference to it...

Would anybody advise on this issue? Many thanks.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see if this suits

 
Biliang Zhou
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Man, you are really the problem-cracker!!!

And I added several lines so that I can filter components with a given property:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if(comp[x] instanceof JButton &&((JButton)comp[x]).getText().equals("OK"))

{comp[x].setBackground(oKButtonColor);}

if(comp[x] instanceof JButton &&((JButton)comp[x]).getText().equals("Cancel"))

{comp[x].setBackground(cancelButtonColor);}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I used short circuit "&&" so that if the component is not a JButton, the type casting won't take place.

Now I have been able to set a background color to the whole GUI, while setting specific colors to certain components.

Thank you!
[ November 02, 2006: Message edited by: Biliang Zhou ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic