GUI scroll inside a panel
1 次查看(过去 30 天)
显示 更早的评论
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
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 个)
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.
0 个评论
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])
0 个评论
另请参阅
类别
在 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!