Positioning components in a large uipanel

7 views (last 30 days)
Jonathan Foster
Jonathan Foster on 30 Nov 2018
Commented: Luna on 30 Nov 2018
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 Comments
Bruno Luong
Bruno Luong on 30 Nov 2018
Your code works fine with me, R2018b, Windows 10, Laptop PC
test.png
Jonathan Foster
Jonathan Foster on 30 Nov 2018
I'm 2017b, Windows 7 - looks like this issue might be very OS/matlab version specific.

Sign in to comment.

Answers (2)

Jonathan Foster
Jonathan Foster on 30 Nov 2018
I've managed to work around this issue by putting the axis inside another uipanel (which doesn't seem to be affected if its parent uipanel is very tall) ie:
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]);
p3 = uipanel(p2,'Units','pixels','Position',[0 0 200 200],'BorderType','none');
a2 = axes(p3,'Units','normalized','Position',[0 0 1 1]);
tb2 = uicontrol(p2,'Style','text','Units','pixels','Position',[250 0 150 50],'String','some text','FontSize',14);
There seems to be some kind of bug when using these very tall uipanels, but it must be quite isolated, as a few people have commented to say that their computer/version of Matlab draws the figure correctly.

Luna
Luna on 30 Nov 2018
Edited: Luna on 30 Nov 2018
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
  1 Comment
Jonathan Foster
Jonathan Foster on 30 Nov 2018
The uipanels in your example are smaller than the figure, so it works fine. If you change Position(4) of each of the uipanels to above 1.2 or so, the components start drifting upwards again. The information I'm trying to display is larger than a full-screen figure, so I need the uipanel to be larger.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!