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

4 visualizaciones (últimos 30 días)
ALESIA
ALESIA el 14 de Nov. de 2024
Comentada: ALESIA el 14 de Nov. de 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

Respuesta aceptada

Taylor
Taylor el 14 de Nov. de 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 comentarios
Taylor
Taylor el 14 de Nov. de 2024
You're most welcome! If you're satisfied with the answer please hit the "accept this answer" button.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre App Building en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by