GUI scroll inside a panel
1 view (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 24 Feb 2011
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.
Answers (3)
Lisa liu
on 5 Mar 2014
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 Comments
David
on 14 May 2014
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 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!