Enabling scrolling in frame

How do I add scrolling in a frame? I created several pushbuttons inside a frame (frame as parent of pushbuttons). There are many pushbuttons which frame cannot accomodate, so I want to add scrolling to access all the pushbuttons.

I tried with setting ‘Scrollable’ to true, but it doesnot add scrolling functionality to the frame. Am I wrong assuming this will enable a scrollbar on the frame?

Thank you!

Following is what documentation read:

“Scrollable
Boolean.
Used for frame and edit style uicontrols, this property indicates if the uicontrol must have scrolling capabilities (%T) or not (default %F).
For frame this value must be set at creation.”

Hello,

Currently, scrollable can only be used with frame or figure in layout gridbag

h = 500; w = 300;
delete(get("scroll"));
f = figure(...
    "infobar_visible", "off", ...
    "toolbar", "none", ...
    "menubar_visible", "off", ...
    "toolbar_visible", "off", ...
    "menubar", "none", ...
    "default_axes", "off", ...
    "layout", "border", ...
    "axes_size", [w h], ...
    "background", -2, ...
    "tag", "scroll");

fr = uicontrol(f, ...
    "style", "frame", ...
    "backgroundcolor", [1 1 1], ...
    "layout", "gridbag", ...
    "scrollable", "on");

n = 10;
for i = 1:n
    c = createConstraints("gridbag", [1, i, 1, 1], [0, 0], "none", "center", [0, 0], [200, 100]);
    ui = uicontrol(fr, ...
        "style", "pushbutton", ...
        "constraints", c, ...
        "string", "Button " + string(i), ...
        "callback", sprintf("disp(""click click %d"")", i));
end

//you can add an empty frame at the end 
//to push elements to the top when the main frame is not full
uicontrol(fr, ...
    "style", "frame", ...
    "constraints", createConstraints("gridbag", [1, n + 1, 1, 1], [1, 1], "both", "center", [1, 1], [200, 1]));

Antoine

2 Likes