Matlab,GUI,在Pane中滚动内容。如何隐藏溢出?

时间:2012-02-02 20:33:38

标签: user-interface matlab scroll panel

我正在尝试制作一个带有滚动内容的面板的Matlab GUI。当滚动出子面板时,我在隐藏溢出内容时遇到问题。

我从这篇SO帖子中获得了滚动条的代码:Adding scroll bar in subplots within GUI

尝试以下代码。我有一个图形,一个外面板(小于图形,图中的孩子),滚动面板(高度大于图形,子到外面板),滚动条和文本字段出现在滚动窗格(子项到滚动面板)。

当你尝试代码时,你会看到文本字符串,它只是重复的字母,在图的整个长度上下滚动,但滚动面板停在外面板边界的边缘。 / p>

如何更正此问题。感谢。

function guitest
    scrsz = get(0,'ScreenSize');

    height = scrsz(4)*7/8;
    width = scrsz(3)*2/3;
    leftmargin = 10;
    rightmargin = 10;

    % figure 
    handles.hFig = figure('Visible','on',...
                    'Position', [scrsz(3)/8 scrsz(4)/10 width height],...
                'Name', 'Tap Toolbar Report',...
                'NumberTitle', 'off',...
                'Color', [0.75 0.75 0.75],...
                'ToolBar','none',...
                'MenuBar','none',...
                'Resize','off');

    % subpanel in the figure for scrolling
    handles.hOut = uipanel('Parent',handles.hFig,...
                  'BackgroundColor', [0.85 0.85 0.85],...
                  'BorderWidth', 0,...
                  'Units', 'pixels',...
                  'Position',[leftmargin 100 width-2*leftmargin height-200]);

    hPanheight = 2000;

    handles.hPan = uipanel('Parent',handles.hOut,...
              'BackgroundColor', [0.85 0.85 0.85],...
              'BorderWidth', 0,...
              'Units', 'pixels',...
              'Position',[0 0 width-2*leftmargin-19 hPanheight]);

    str = sprintf('a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz');
    uicontrol('Parent', handles.hPan,'Style','text','String',str,'FontSize', 10,'FontWeight','bold', 'HorizontalAlignment', 'left',...
            'Position',[10 20 20 1960],'BackgroundColor', [0.85 0.85 0.85]);          

    handles.hSld = uicontrol('Style', 'slider',...
                'BackgroundColor', [0.8 0.8 0.8], ...
                'Position', [width-leftmargin-20 101 19 height-202],...
                'Callback', {@onSlide,handles.hPan,handles.hOut});
    set(handles.hSld,'Value',1);
    onSlide(handles.hSld,'',handles.hPan,handles.hOut)
end 

function onSlide(hSld,~,hPan,hOut)
    %# slider value
    offset = get(hSld,'Value');

    %# update panel position
    p = get(hPan, 'Position');  %# panel current position
    ph = get(hOut, 'Position');
    set(hPan, 'Position',[p(1) -offset*(p(4)-ph(4)) p(3) p(4)])
end

1 个答案:

答案 0 :(得分:1)

我会使用内置滚动功能的容器对象。看看:

help uitable
help uitree