MATLAB: How to get the handle of all static texts present in a uipanel to change their backgroung color

matlab gui

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?

Best Answer

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!