Positioning components in a large uipanel

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 comentarios

Walter Roberson
Walter Roberson el 30 de Nov. de 2018
The two sides look the same to me on R2017b and R2018b on my OS-X system.
Luna
Luna el 30 de Nov. de 2018
Editada: Luna el 30 de Nov. de 2018
Have you ever tried to put your figure and the other uicomponents units property normalized?
Why are you using pixels?
It does not fit my screen btw. figure flows. Also left & right side are different. R2018a - W8
Luna
Luna el 30 de Nov. de 2018
Also check gui layout toolbox in File Exchange
It gives you the best solution of placing ui elements in a figure in order, creating tabs, panels, containers, boxes, frames,.. etc
Jonathan Foster
Jonathan Foster el 30 de Nov. de 2018
@Walter, weird, this is what I see:
figure_uipanel.png
Luna
Luna el 30 de Nov. de 2018
Same in my machine.
Jonathan Foster
Jonathan Foster el 30 de Nov. de 2018
@Luna, I'm using pixels for convenience basically - I'm trying to replicate a system diagram and the position information I have on each of the components is in pixels. I can look into converting them and see what happens.
Bruno Luong
Bruno Luong el 30 de Nov. de 2018
Your code works fine with me, R2018b, Windows 10, Laptop PC
test.png
Jonathan Foster
Jonathan Foster el 30 de Nov. de 2018
I'm 2017b, Windows 7 - looks like this issue might be very OS/matlab version specific.

Iniciar sesión para comentar.

Respuestas (2)

Jonathan Foster
Jonathan Foster el 30 de Nov. de 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 el 30 de Nov. de 2018
Editada: Luna el 30 de Nov. de 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 comentario

Jonathan Foster
Jonathan Foster el 30 de Nov. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Productos

Versión

R2017b

Etiquetas

Preguntada:

el 30 de Nov. de 2018

Comentada:

el 30 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by