Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2005

Tip: Looking for answers? Try searching our database.

How to change color of text in disabled JTree?

Thread view: 
Rene Ruppert - 14 Feb 2005 16:07 GMT
Hi,

When using JTree.setEnabled(false); all entries turn into the standard metal
disabled grey.
Is there a way to change this color?
I tried my own item renderer and setting the foreground color of the item
JLabels but wthout success.

Thanks.

cu
Ren?
Rene Ruppert - 14 Feb 2005 16:14 GMT
An addon: setting "secondary2" in the DefaultMetalTheme is no solution for
me since it changes all disabled colors but not only JTree.
John McGrath - 14 Feb 2005 21:22 GMT
> When using JTree.setEnabled(false); all entries turn into the standard
> metal disabled grey.
> Is there a way to change this color?
> I tried my own item renderer and setting the foreground color of the
> item JLabels but wthout success.

You need to enable the renderer component.  The renderer sets the enabled
state of the renderer component (a JLabel) to the enabled state of the
JTree.  JLabel ignores the foreground color and paints itself differently
when it is disabled.  See the getTreeCellRendererComponent() method of
DefaultTreeCellRenderer for more details.

Signature

Regards,

John McGrath

Rene Ruppert - 15 Feb 2005 11:04 GMT
Hi,

> You need to enable the renderer component.  The renderer sets the enabled
> state of the renderer component (a JLabel) to the enabled state of the
> JTree.  JLabel ignores the foreground color and paints itself differently
> when it is disabled.  See the getTreeCellRendererComponent() method of
> DefaultTreeCellRenderer for more details.

I do already override getTreeCellRendererComponent() and I use
myLabel.setForeground() to change the color. This works fine as long as the
corresponding tree is setEnabled(true). As soon as I call
JTree.setEnabled(false) the setForeground() looses its effect.
What now?

Regards,
Ren?
John McGrath - 15 Feb 2005 11:51 GMT
> > You need to enable the renderer component.
>
[quoted text clipped - 3 lines]
> JTree.setEnabled(false) the setForeground() looses its effect.
> What now?

Enable the renderer component.

The component that you return from the getTreeCellRendererComponent() is
what paints the cell.  If that component is disabled, it will paint the
cell so as to appear disabled, and it ignores the foreground color.  You
need to enable the component, so it will not paint the cell so as to
appear disabled.

If this still does not make sense to you, please post the code of your
getTreeCellRendererComponent() method.

Signature

Regards,

John McGrath

Rene Ruppert - 15 Feb 2005 12:21 GMT
Hi,

> Enable the renderer component.

Okay, now I understand your previous post! That's it of course...a simple
myLabel.setEnabled(true) before returning it did the job.

Thanks.

Ren?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.