page that can be scrolled based on the data to be displayed
3 views (last 30 days)
Show older comments
ALESIA MEMUSHAJ
on 14 Nov 2024
Commented: ALESIA MEMUSHAJ
on 14 Nov 2024
I would like to create a user interface in MATLAB with a scrollable panel. The purpose is to display a list of checkboxes, where the number of checkboxes corresponds to the number of electrodes (or channels) I have. The issue is that I would like the panel to be scrollable when there are many checkboxes, but I also want the panel itself to remain fixed in place without moving as a whole.
numElectrodes = 32; % just in this case
newFigure = uifigure('Name', 'Visualize Channels', ...
'Position', [20, screenSize(4)/4, screenSize(3)/2, screenSize(4)/1.5]);
channelPanel = uipanel(newFigure, 'Position', [500,100,200,480], 'Title', 'Delete Channels',Scrollable='on');
checkboxHandles = zeros(1, numElectrodes);
scrollAxes = axes(channelPanel, 'Position', [0, 0, 1, 1], 'Visible', 'off');
set(scrollAxes, 'Units', 'pixels');
panelHeight = numElectrodes * 20;
set(scrollAxes, 'Position', [0, 0, 1, panelHeight/500]);
for i = 1:numElectrodes
checkboxHandles(i) = uicontrol(channelPanel, 'Style', 'checkbox', ...
'String', sprintf('Canale %d', i), ...
'Position', [10, panelHeight - (i * 20), 150, 25]);
end
set(newFigure, 'WindowScrollWheelFcn', @(src, event) scrollPanel(event, channelPanel, panelHeight));
function scrollPanel(event, channelPanel, panelHeight)
panelPos = get(channelPanel, 'Position');
newY = panelPos(2) + event.VerticalScrollCount * 10;
newY = max(min(newY, 0), 1 - panelHeight / 500);
set(channelPanel, 'Position', [panelPos(1), newY, panelPos(3), panelPos(4)]);
end
Accepted Answer
Taylor
on 14 Nov 2024
I believe a uitree for check boxes is what you want. If you use App Designer, a scroll bar is automatically added if you have more nodes that are able to be displayed. Alternatively, you could use a uilistbox. Just make sure you have multiselect turned on.
2 Comments
Taylor
on 14 Nov 2024
You're most welcome! If you're satisfied with the answer please hit the "accept this answer" button.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!