Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Change text color of uicontrol whose 'Enable' property is 'off'

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

From: Nate Jensen

Date: 9 Oct, 2011 18:34:10

Message: 1 of 7

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?

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

From: matt dash

Date: 10 Oct, 2011 17:05:26

Message: 2 of 7

"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])

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

From: Nate Jensen

Date: 10 Oct, 2011 17:45:29

Message: 3 of 7

"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.

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

From: Steven_Lord

Date: 10 Oct, 2011 18:01:06

Message: 4 of 7



"Nate Jensen" <natejensen88@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
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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

From: Nate Jensen

Date: 10 Oct, 2011 20:08:07

Message: 5 of 7

"Steven_Lord" <slord@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
> slord@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.

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

From: matt dash

Date: 18 Oct, 2011 17:33:26

Message: 6 of 7

"Nate Jensen" wrote in message <j6vjb7$7dj$1@newscl01ah.mathworks.com>...
> "Steven_Lord" <slord@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
> > slord@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.

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...

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

From: Nate Jensen

Date: 18 Oct, 2011 17:57:11

Message: 7 of 7

"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.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us