matlab - Matlab指南GUI工具/按钮?
问题描述
我已经在 matlab GUI 上工作了一段时间,终于让它做我想做的事情,现在我只是在努力让它变得更简洁和用户友好。我有 5 个面板并将它们全部堆叠在一起,并在面板顶部添加了 5 个按钮。有没有办法通过按下按钮将面板带到前面?
function togglebutton2_Callback(hObject, eventdata, handles)
这是我对按钮的回电。有什么我可以通过单击使面板显示在前面的添加内容吗?谢谢
解决方案
有许多工具/示例可用于创建已提交到MathWorks 文件交换的选项卡式面板。他们中的任何一个都可能会做你想做的事。但是,您也可以使用uibuttongroup
. 这是一个选项卡式面板设计的简单示例:
function tab_panel
hFigure = figure('Units', 'pixels', 'Position', [200 200 320 320]);
hPanel1 = uipanel(hFigure, 'Units', 'pixels', 'Position', [10 10 300 270], ...
'BackgroundColor', 'r');
hPanel2 = uipanel(hFigure, 'Units', 'pixels', 'Position', [10 10 300 270], ...
'BackgroundColor', 'g', 'Visible', 'off');
hPanel3 = uipanel(hFigure, 'Units', 'pixels', 'Position', [10 10 300 270], ...
'BackgroundColor', 'b', 'Visible', 'off');
hGroup = uibuttongroup(hFigure, 'Units', 'pixels', 'Position', [10 280 300 30], ...
'BorderType', 'none', 'SelectionChangedFcn', @switch_panel);
hButton1 = uicontrol(hGroup, 'Style', 'toggle', 'Position', [0 0 40 30], ...
'String', 'Red');
hButton2 = uicontrol(hGroup, 'Style', 'toggle', 'Position', [40 0 40 30], ...
'String', 'Green');
hButton3 = uicontrol(hGroup, 'Style', 'toggle', 'Position', [80 0 40 30], ...
'String', 'Blue');
function switch_panel(~, eventData) % Nested callback function
switch eventData.NewValue
case hButton1
set(hPanel1, 'Visible', 'on');
set([hPanel2 hPanel3], 'Visible', 'off');
case hButton2
set(hPanel2, 'Visible', 'on');
set([hPanel1 hPanel3], 'Visible', 'off');
case hButton3
set(hPanel3, 'Visible', 'on');
set([hPanel1 hPanel2], 'Visible', 'off');
end
end
end
这将创建三个红色、绿色和蓝色的面板,以及三个切换按钮。回调由嵌套函数处理。按下按钮将通过打开其可见性同时关闭所有其他面板的可见性来显示相应的彩色面板。
尽管这是一个编程示例,但应该很容易将其调整为 GUIDE 设计的 GUI。
推荐阅读
- javascript - bootstrap 4 下拉隐藏位置粘性 div
- python - 检测英文单词和nltk的单词语料库
- javascript - 动态导入在 netlify 中不起作用(reactjs)
- javascript - 如何将跨度的高度设置为同一行中跨度的最大高度?
- java - 文本在 JLabel 中重复
- excel - 使用 VBA 和对话框以不同方式另存为 CSV 结果
- python - 如何将 Odoo 10 文件存储移动到不同的目录
- mule-studio - 数据编织转换后如何替换<和paylaod
- ipv6 - 可以同时获取我的公共 ipv4 和 ipv6 地址(whatsmyipaddresss.com 可以做到)这是怎么做到的?
- reactjs - 使用 ownProps / typescript 的 React/Redux Connect 问题