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

1 次查看(过去 30 天)
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?

采纳的回答

Geoff Hayes
Geoff Hayes 2016-6-12
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!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by