Positioning components in a large uipanel
7 ビュー (過去 30 日間)
古いコメントを表示
I'm seeing some unexpected results when adding components to a very tall uipanel. Hopefully the code below demonstrates the problem. I've created a figure with two uipanels, both much taller than the figure they're contained in. Each uipanel has identical components, an axis and a text field positioned such that they should be at the bottom of the uipanel.
in the left uipanel that's 2000 pixels high, as expected, the axis and text field both are displayed at the bottom of the uipanel. But in the right uipanel that's 2500 pixels high, the axis has started drifting up the uipanel (the text field stays at the bottom of the panel, as I would expect).
f = figure('Units','pixels','Position',[0 0 1000 800]);
p = uipanel(f,'Units','pixels','Position',[0 0 400 2000]);
a = axes(p,'Units','pixels','Position',[0 0 200 200]);
tb = uicontrol(p,'Style','text','Units','pixels','Position',[250 0 150 50],'String','some text','FontSize',14);
p2 = uipanel(f,'Units','pixels','Position',[500 0 400 2500]);
a2 = axes(p2,'Units','pixels','Position',[0 0 200 200]);
tb2 = uicontrol(p2,'Style','text','Units','pixels','Position',[250 0 150 50],'String','some text','FontSize',14);
My understanding is that the position property of both the axis and text field are relative to the bottom left corner of the parent uipanel - so I don't understand why the axis doesn't plot in the bottom left of the second uipanel. The same thing occurs when using annotations (but not other uicontrol elements). Does anyone know how to resolve this?
The context for this problem is I want to have a large uipanel that can be scrolled around (a bit like Simulink) but when the height of the uipanel goes past ~2000 pixels, components within the uipanel start plotting higher up than expected.
I'm using Matlab R2017b.
8 件のコメント
回答 (2 件)
Jonathan Foster
2018 年 11 月 30 日
1 件のコメント
Luna
2018 年 11 月 30 日
This still does not seem OK in my machine. Maybe have look of that link below?
Luna
2018 年 11 月 30 日
編集済み: Luna
2018 年 11 月 30 日
Try this, you can also get the pixel positions in the last line I have commented.
f = figure('Units','normalized','Position',[0.1 0.1 0.8 0.8]);
p = uipanel(f,'Units','normalized','Position',[0 0 0.5 1]);
a = axes(p,'Units','normalized','Position',[0.05 0.75 0.9 0.2]);
tb = uicontrol(p,'Style','text','Units','normalized','Position',[0.025 0.1 0.2 0.05],'String','some text','FontSize',14);
p2 = uipanel(f,'Units','normalized','Position',[0.5 0 0.5 1]);
a2 = axes(p2,'Units','normalized','Position',[0.05 0.75 0.9 0.2]);
tb2 = uicontrol(p2,'Style','text','Units','normalized','Position',[0.025 0.1 0.2 0.05],'String','some text','FontSize',14);
getpixelposition(p2) % you can still get the pixels position of each element
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!