필터 지우기
필터 지우기

How can I control the stacking order of objects in appdesigner?

조회 수: 35 (최근 30일)
Kevin J. Delaney
Kevin J. Delaney 2018년 1월 4일
답변: Adam Danz 2023년 3월 17일
How can I control the stacking order of objects in appdesigner? It seems to be determined by the order in which the panels or axes are created. What if I want an object created later to slide underneath earlier objects?

채택된 답변

Sean de Wolski
Sean de Wolski 2018년 1월 4일
You can control the order of the 'Children' of a graphics object directly:
fig = uifigure;
panel1 = uipanel(fig, 'BackgroundColor', 'b');
panel2 = uipanel(fig, 'BackgroundColor', 'r');
fig.Children = flip(fig.Children)
  댓글 수: 6
Sean de Wolski
Sean de Wolski 2018년 2월 8일
I was just copying what you had to show that it works, they were adjacent in the question so assumed it was all in your startup. I wouldn't recommend calling uipanel in startup!
It's definitely a fair enhancement request to have them be adjustable in the component browser on the right.
paul harder
paul harder 2020년 8월 28일
Yes, intuitively I should be able to drag panels up and down the component browser to order the stacking. It seems like the stack order is tied to the order of creation, which is super inflexible.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Kevin J. Delaney
Kevin J. Delaney 2018년 2월 7일
Inspired by Sean's answer, I wrote the attached utility for use in the startupFcn:
move_to_bottom(app.UIFigure, app.Axes);

Wouter
Wouter 2018년 2월 14일
You could also keep a list of handles; e.g. in the variable background and than move all of these to the background.
hfig = uifigure; % create figure
hax = uiaxes(hfig); % create axis
foreground = plot(hax,rand(1,100),'r'); % create red line
hold(hax,'on');
for ind = 1:10
% this moves the foreground plot to the background...
background(ind) = plot(hax,rand(1,100),'k'); % create 10 ack lines (on top of red line)
end
% move the background lines to the background!
ch = get(hax,'children'); % get all plots from hax
[~,neworder] = sort(ismember(ch,background)); % reorder the handles to move the background lines to the background
set(hax,'children',ch(neworder)); % set the new order of all lines

Adam Danz
Adam Danz 2023년 3월 17일
Starting in MATLAB R2023a you can use uistack to control the stacking order of ui components in a uifigure such as in App Designer.

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by