GUI scroll inside a panel

4 ビュー (過去 30 日間)
Christophe
Christophe 2011 年 2 月 24 日
回答済み: David 2014 年 5 月 14 日
Hello,
I am trying to create a scroll bar in order to scroll elements which are inside a panel.
I have one main panel with a slider and a sub panel inside. When I scroll the sub panel objects, they do not disappear when scrolling up or down. The sub panel do disappear but not the edit box.
Here is my code
function main hpanel=uipanel(figure,'Position',[0.2 0.2 0.6 0.6]); panel2 = uipanel('Unit','normalized','Position',[.2 .1 .5 .5],'Parent',hpanel);
model_edit = uicontrol('Style','edit','Parent',panel2,'BackgroundColor',[1 1 1],'Unit','normalized','Position',[.2 .8 .4 .1]); pos = get(panel2,'Position');
hpop = uicontrol('Style', 'slider','Position', [2 0 20 250],'Value',1,'Callback', {@slider_callback,panel2,pos},'Parent',hpanel); end
function slider_callback(src,event,arg1,pos) slidervalue= get(src,'Value'); new_pos = pos(2)-slidervalue+1; set(arg1,'Position',[pos(1) pos(2)-slidervalue+1 pos(3) pos(4)]); end
Thank you in advance,
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 2 月 24 日
Which matlab version are you using and on which OS ?
There was a bug about this a few versions back, that uicontrols were not being clipped by panel boundaries.

サインインしてコメントする。

回答 (3 件)

Christophe
Christophe 2011 年 2 月 25 日
Thank you for your answer. I am using the 2007b version but I tried on 2010a and it was the same bug. My OS is Vista SP2, I will try on XP later.

Lisa liu
Lisa liu 2014 年 3 月 5 日
hello Christophe ,i have met the same question as yours ,and i haven't solved it yet. I wonder how you solve this problem.Thank you . i work on matlab2012a,if this is a bug,then it hasn't be fixed.

David
David 2014 年 5 月 14 日
The problem is that uicontrols are not clipped, as in they don't disappear when they move outside of the uipanel that holds the second uipanel that you move in order to scroll. This is apparently because the uicontrols are always rendered on top of any backgrounds so the ordering makes it so uicontrols don't disappear. The workaround I developed, which, I will admit, is rather klug-y, is to make two uicontrols that are text, that span the distance from the top of the uipanel to the edge of the window and the bottom of the uipanel to the edge of the window. These are text boxes with a background the same color as the window and text that is the same color as the background (otherwise they don't show up at all). Basic code below.
David
p2050_pos = [0.1 0.1 windowwidth/screensize(3)+0.05 0.85]; % position of my outer control panel
%uicontrols spanning the space where I want things to disappear. uicontrol('Style', 'Text', 'Parent',S.fh,'Units','normalized', 'Position', [ p2050_pos(1), 0, p2050_pos(3), p2050_pos(2)], 'BackgroundColor', [1 1 1],'string','woot!','ForegroundColor',[1 1 1]) uicontrol('Style', 'Text', 'Parent',S.fh,'Units','normalized', 'Position', [ p2050_pos(1), p2050_pos(2)+p2050_pos(4), p2050_pos(3), 1], 'BackgroundColor', [1 1 1],'string','woot!','ForegroundColor',[1 1 1])

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by