page that can be scrolled based on the data to be displayed

조회 수: 4 (최근 30일)
ALESIA
ALESIA 2024년 11월 14일
댓글: ALESIA 2024년 11월 14일
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
Taylor 2024년 11월 14일
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
Taylor 2024년 11월 14일
You're most welcome! If you're satisfied with the answer please hit the "accept this answer" button.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by