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

5 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 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!

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by