uipanel position jumping randomly

조회 수: 1 (최근 30일)
Martin Privat
Martin Privat 2022년 10월 26일
답변: Martin Privat 2022년 11월 4일

On 2021b, the following code runs with two different behaviors

Either the panel has the correct position (first picture) or it is too big (second picture)>
f = figure('PaperUnits','centimeters', ...
'PaperSize',[21 29.7], ...
'PaperPosition',[0 0 21 29.7], ...
'PaperPositionMode','manual', ...
'PaperType','A4',...
'Units','centimeters',...
'Position',[0 0 21 29.7],...
'Resize','off',...
'MenuBar','none',...
'ToolBar','none');

page_margin = 1.5;
pos = [page_margin page_margin 21-2*page_margin 29.7-2*page_margin];
main_panel = mypanel(f,pos);

function p = mypanel(parent,pos)
p = uipanel(parent,...
'Units','centimeters',...
'Position',pos,...
'BorderType','none',...
'BackgroundColor','w',...
'ShadowColor','w');
end

  댓글 수: 1
Martin Privat
Martin Privat 2022년 11월 4일
Here is what the problem looks like on two runs of the code

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

채택된 답변

Martin Privat
Martin Privat 2022년 11월 4일
Many thanks to Daniele Sportillo for finding a solution, this seems to do the trick:
f = figure()
pause(0.1)
set(f,'PaperUnits','centimeters', ...
'PaperSize',[21 29.7], ...
'PaperPosition',[0 0 21 29.7], ...
'PaperPositionMode','manual', ...
'PaperType','A4',...
'Units','centimeters',...
'Position',[0 0 21 29.7],...
'Resize','off',...
'MenuBar','none',...
'ToolBar','none');
page_margin = 1.5;
pos = [page_margin page_margin 21-2*page_margin 29.7-2*page_margin];
main_panel = mypanel(f,pos);

추가 답변 (0개)

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by