user3241316
user3241316

Reputation: 167

GUI scrollbar error

I'm trying to create a scrolling list within a GUI using nested panels. However, whenever I try to move the scrollbar in the GUI, I receive this error:

??? Error using ==> PyroGUI>slider Too many input arguments.
??? Error while evaluating uicontrol Callback

Here is my code:

screensize=get(0,'ScreenSize');

handles.fig=figure('Position',[100 100 screensize(3)-150 screensize(4)-150]);


handles.hpanel=uipanel(handles.fig,'Position',[0.005 0.01 0.99 0.99],'Title','Panel');
handles.hsp = uipanel('Parent',handles.hpanel,'Title','Subpanel','FontSize',12,...
              'Position',[.025 .05 .3 .935]);

handles.hpop = uicontrol('Style', 'slider',...
       'Position', [20 30 20 700],...
       'Min',1,'Max',700,'Value',700,...
       'callback', {@slider,handles.hsp});

handles.pos=get(handles.hpanel,'Position');   
function slider()
        slidervalue=get(handles.hpop,'Value');
        set(handles.hpanel,'Position',[handles.pos(1) handles.pos(2)-slidervalue+1 handles.pos(3) handles.pos(4)]);
    end

Any ideas as to what could be causing this?

Upvotes: 0

Views: 65

Answers (1)

tim
tim

Reputation: 10176

If you provide a callback function for uicontrol, it always needs two input arguments like this (even if you don't need them)

function slider(hobj, evnt)
        slidervalue=get(handles.hpop,'Value');
        set(handles.hpanel,'Position',[handles.pos(1) handles.pos(2)-slidervalue+1 handles.pos(3) handles.pos(4)]);
    end

Edit: See here http://www.mathworks.de/de/help/matlab/creating_guis/examples-programming-gui-components.html

Upvotes: 1

Related Questions