How to get parent name of a child GUI component?

10 views (last 30 days)
Hi everybody,
I have a figure with 'Name' property: 'My figure' and 'Tag' property: 'figure1'.
In this figure, I have a push button with 'Name' property: 'Push me' and 'Tag' property: 'pushbutton1'
How can I get the push button's parent name in a programmatic GUI?
Is its parent name 'Myfigure' or 'figure1'?
% Code generated by FIG2M made by Thomas Montagnon (The MathWorks France)
% Great thanks to him
% --- FIGURE -------------------------------------
handles.figure1 = figure( ...
'Tag', 'figure1', ...
'Units', 'characters', ...
'Position', [102.8 24.3076923076923 114 32.9230769230769], ...
'Name', 'figure1', ...
'MenuBar', 'none', ...
'NumberTitle', 'off', ...
'Color', [0.941 0.941 0.941]);
% --- PUSHBUTTONS -------------------------------------
handles.pushbutton6 = uicontrol( ...
'Parent', handles.figure1, ...
'Tag', 'pushbutton6', ...
'Style', 'pushbutton', ...
'Units', 'characters', ...
'Position', [13.4 22.9230769230769 24.4 1.92307692307692], ...
'String', 'Push Button');
a=get(handles.pushbutton6,'parent') % a is a double, I don't know how to get parent name from it.

Accepted Answer

Orion
Orion on 20 Oct 2014
Hi,
Actually, more than a double, a is a handle. (try ishandle(a))
In your case, with
a=get(handles.pushbutton6,'parent')
a is the handle of the parent of handles.pushbutton6, which here is the figure.
And to get the name of this (which usually is different of the tag) :
get(a,'Name')
ans =
figure1

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!