how to get the handle of all static texts present in a uipanel to change their backgroung color?

2 views (last 30 days)
I know how to Change the backgound color of a Static Text.
set(handles.text1,'BackgroundColor','w');
set(handles.text2,'BackgroundColor','w');
But I want to Change the Background of all the Static Texts present in the uipanel. So, how can i get the handle of all the Static Texts and Change their backgound Color at once?

Accepted Answer

Geoff Hayes
Geoff Hayes on 12 Jun 2016
Harish - you can use the findobj function to get all the handles that match a certain criteria and then change the background colour for each. For example, suppose that you have a pushbutton callback that colours the background red for each of the static texts in your panel. We use findobj as
function pushbutton1_Callback(hObject, eventdata, handles)
hStaticTexts = findobj('Parent',handles.uipanel1, 'Style','text');
if ~isempty(hStaticTexts)
set(hStaticTexts,'BackgroundColor','r');
end
hStaticTexts is an array of handles to the graphics objects whose parent is handles.uipanel1 and whose style is text.
Try the above and see what happens!

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!