wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes change the default grey of setEnable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "change the default grey of setEnable" Watch "change the default grey of setEnable" New topic
Author

change the default grey of setEnable

Babis Papadopoulos
Greenhorn

Joined: Dec 11, 2012
Posts: 17
How I can change the default background grey when I check the setEnable as false?
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

You could redefine the component and override setEnabled(boolean enabled) to also set the background to the desired color.


The quieter you are, the more you are able to hear.
Babis Papadopoulos
Greenhorn

Joined: Dec 11, 2012
Posts: 17
I do not understand .. How would I do this? boolean enables takes as parameter only True or False..
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

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"


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

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

Joined: Dec 11, 2012
Posts: 17
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

Joined: May 03, 2008
Posts: 4531
    
    5

Babis Papadopoulos wrote:... when I check the setEnable as false?


When you check what setEnable as false? Where?
Babis Papadopoulos
Greenhorn

Joined: Dec 11, 2012
Posts: 17
I can't find answer of my question in all of the internet!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

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

Joined: Jun 19, 2010
Posts: 825
    
    5

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

Joined: Dec 11, 2012
Posts: 17
yes, It seems a little behind the original image
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

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

Joined: Dec 11, 2012
Posts: 17
That's it!! I had not seen!

Thank you very much!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: change the default grey of setEnable