Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change text color of uicontrol whose 'Enable' property is 'off'

51 views
Skip to first unread message

Nate Jensen

unread,
Oct 9, 2011, 2:34:10 PM10/9/11
to
I would like to change the text color of a uicontrol whose 'Enable' property is set to 'off'

Is there a way to do this?

matt dash

unread,
Oct 10, 2011, 1:05:26 PM10/10/11
to
"Nate Jensen" wrote in message <j6spf2$pqn$1...@newscl01ah.mathworks.com>...

> I would like to change the text color of a uicontrol whose 'Enable' property is set to 'off'
>
> Is there a way to do this?

Does being not-enabled specifically prevent this? Are you asking for an automatic method, like whenever you set something's enable to "off" it automatically recolors it too? And are you sure you dont just want to set "enable" to "disabled" (I've never found a good use for enable=off)

f=findobj(gcf,'type','uicontrol','enable','off')
set(f,'color',[1 0 0])

Nate Jensen

unread,
Oct 10, 2011, 1:45:29 PM10/10/11
to
"matt dash" wrote in message <j6v8km$r3q$1...@newscl01ah.mathworks.com>...

> Does being not-enabled specifically prevent this? Are you asking for an automatic method, like whenever you set something's enable to "off" it automatically recolors it too? And are you sure you dont just want to set "enable" to "disabled" (I've never found a good use for enable=off)
>
> f=findobj(gcf,'type','uicontrol','enable','off')
> set(f,'color',[1 0 0])

Does it? I did not know that. Is there a workaround?

I'm not sure exactly what you mean by 'automatic'. I don't want to change any Matlab defaults. I just would like to know if there is a way to change the color of the text when the 'Enable' property is set to 'off'. A simple line of code.

I'm also not sure what you mean by 'disabled'? Doesn't setting 'Enable' to 'off' disable the uicontrol?

Currently I am using Java to get around this problem.

Thanks for the help. If you have any suggestions, let me know.

Steven_Lord

unread,
Oct 10, 2011, 2:01:06 PM10/10/11
to

"Nate Jensen" <nateje...@gmail.com> wrote in message
news:j6vavp$674$1...@newscl01ah.mathworks.com...


> "matt dash" wrote in message <j6v8km$r3q$1...@newscl01ah.mathworks.com>...
>> Does being not-enabled specifically prevent this? Are you asking for an
>> automatic method, like whenever you set something's enable to "off" it
>> automatically recolors it too? And are you sure you dont just want to set
>> "enable" to "disabled" (I've never found a good use for enable=off)
>>
>> f=findobj(gcf,'type','uicontrol','enable','off')
>> set(f,'color',[1 0 0])
>
> Does it? I did not know that. Is there a workaround?
>
> I'm not sure exactly what you mean by 'automatic'. I don't want to change
> any Matlab defaults. I just would like to know if there is a way to
> change the color of the text when the 'Enable' property is set to 'off'.
> A simple line of code.
>
> I'm also not sure what you mean by 'disabled'? Doesn't setting 'Enable'
> to 'off' disable the uicontrol?

Write a two-line function to do this.

function disableUicontrolAndChangeColor(uicontrolHandle, desiredColor)
set(uicontrolHandle, 'Enable', 'off', 'Color', desiredColor);

Call this function in your code whenever you need to disable a uicontrol and
change its color. You can write a similar two-line
enableUicontrolAndChangeColor function to reverse the process. You can, of
course, make this more elaborate: some things you might want it to do
include having disableUicontrolAndChangeColor return the color prior to
disabling the uicontrol, or return an onCleanup object that restores the
previous color when deleted, or ...

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Nate Jensen

unread,
Oct 10, 2011, 4:08:07 PM10/10/11
to
"Steven_Lord" <sl...@mathworks.com> wrote in message <j6vbt2$9aj$1...@newscl01ah.mathworks.com>...
> Write a two-line function to do this.
>
> function disableUicontrolAndChangeColor(uicontrolHandle, desiredColor)
> set(uicontrolHandle, 'Enable', 'off', 'Color', desiredColor);
>
> Call this function in your code whenever you need to disable a uicontrol and
> change its color. You can write a similar two-line
> enableUicontrolAndChangeColor function to reverse the process. You can, of
> course, make this more elaborate: some things you might want it to do
> include having disableUicontrolAndChangeColor return the color prior to
> disabling the uicontrol, or return an onCleanup object that restores the
> previous color when deleted, or ...
>
> --
> Steve Lord
> sl...@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Thanks, but there is no property 'Color' for uicontrols. Also, setting 'ForegroundColor' does not work. I am using R2011b. Maybe changes there were changes made to the properties of uicontrols?

h = uicontrol('Style','text','String','a');
set(h,'Enable','off','ForegroundColor','k')

Running the above code does not change the font color.

Thanks for the help though.

matt dash

unread,
Oct 18, 2011, 1:33:26 PM10/18/11
to
"Nate Jensen" wrote in message <j6vjb7$7dj$1...@newscl01ah.mathworks.com>...
Sorry, I was mixing up inactive and off, and wrongly calling inactive disabled. Whew. Maybe this will work for you though:

h = uicontrol('Style','text','String','a');
set(h,'Enable','inactive','ForegroundColor','c')

Using inactive instead of off lets you still change its appearance...

Nate Jensen

unread,
Oct 18, 2011, 1:57:11 PM10/18/11
to
"matt dash" wrote in message <j7kd96$69o$1...@newscl01ah.mathworks.com>...
> Sorry, I was mixing up inactive and off, and wrongly calling inactive disabled. Whew. Maybe this will work for you though:
>
> h = uicontrol('Style','text','String','a');
> set(h,'Enable','inactive','ForegroundColor','c')
>
> Using inactive instead of off lets you still change its appearance...

Awesome thanks for coming back and answering that for me. I appreciate it. Your answer worked.
0 new messages