page that can be scrolled based on the data to be displayed
33 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Taylor
2024-11-14,14:32
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 个评论
Taylor
2024-11-14,15:07
You're most welcome! If you're satisfied with the answer please hit the "accept this answer" button.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!