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

1 回表示 (過去 30 日間)
ALESIA MEMUSHAJ
ALESIA MEMUSHAJ 2024 年 11 月 14 日
コメント済み: ALESIA MEMUSHAJ 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 件のコメント
ALESIA MEMUSHAJ
ALESIA MEMUSHAJ 2024 年 11 月 14 日
thanks!
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 Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by