Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

change the default grey of setEnable

 
Babis Papadopoulos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How I can change the default background grey when I check the setEnable as false?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could redefine the component and override setEnabled(boolean enabled) to also set the background to the desired color.
 
Babis Papadopoulos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not understand .. How would I do this? boolean enables takes as parameter only True or False..
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Babis Papadopoulos wrote:How I can change the default background grey when I check the setEnable as false?


For one specific component or for all instances of a class? For the latter, you should put an appropriate setting in the UIDefaults via the UIManager.

If you want to change a color for all components of all classes, then the correct approach would be to write a theme possibly extending MetalTheme or OceanTheme.

Of course, both these suggestions assume that you are using Swing and the default Look and Feel. A custom or system LaF may require a different approach.

edit: added "Swing and"
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:You could redefine the component and override setEnabled(boolean enabled) to also set the background to the desired color.


Kemal, I like most of your suggestions but I have to say I can't agree with this. Even if you want to take the approach of setting the background color in code every time the enabled status is changed (which too I don't like very much) that can be accomplished with a PropertyChangeListener on the "enabled" property.

Assuming of course that the question pertains to a Swing component.
 
Babis Papadopoulos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry!!
I have JLabel! jlabel with image ... I make the memorycard came and if the player click the label I want to setEnable(false) this label... But I don't want to have this grey but my default image..
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Babis Papadopoulos wrote:... when I check the setEnable as false?


When you check what setEnable as false? Where?
 
Babis Papadopoulos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't find answer of my question in all of the internet!
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Babis Papadopoulos wrote:Sorry!!
I have JLabel! jlabel with image ... I make the memorycard came and if the player click the label I want to setEnable(false) this label... But I don't want to have this grey but my default image..


Are you talking about the dithered monochrome image that JLabel generates to signify the labe is disabled?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Kemal, I like most of your suggestions but I have to say I can't agree with this. Even if you want to take the approach of setting the background color in code every time the enabled status is changed (which too I don't like very much) that can be accomplished with a PropertyChangeListener on the "enabled" property.

Well, now that you've mentioned PropertyChangeListener, I see how wrong I was. I guess I didn't think through the problem well in this case, since I often take the way of creating custom components, so I thought that would be appropriate here. Good to have someone to correct me here, thanks.
 
Babis Papadopoulos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, It seems a little behind the original image
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set the same Icon as the label;s disabledIcon, then a gray disabled version won't be automatically generated and substituted.
 
Babis Papadopoulos
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's it!! I had not seen!

Thank you very much!
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome. But next time you start a thread, please do keep in mind that all we know and understand about your problem is what you tell us -- which in this thread, was precious little. With adequate detail, you would have got a solution with Kemal's first response!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic