0
有没有办法在表格单元格在Matlab GUI中添加一个按钮,以便每个按钮可以执行动作取决于它在哪一行?按钮在Matlab图形用户界面表单元格
Sample of What I am trying to make
有没有办法在表格单元格在Matlab GUI中添加一个按钮,以便每个按钮可以执行动作取决于它在哪一行?按钮在Matlab图形用户界面表单元格
Sample of What I am trying to make
,而不诉诸使用Java控件(类似this可以让你去)你不能做到这一点;但是,您可以在uitable
上设置CellSelectionCallback
,并根据该行确定要执行的操作。
function callback(eventData)
if eventData.Indices(2) == 3
fprintf('Clicked Row %d\n', eventData.Indices(1))
end
end
fig = figure()
data = {'a', '1', 'Click Me';
'b', '2', 'Click Me'};
u = uitable(fig, 'data', data, 'CellSelectionCallback', @(s,e)callback(e));
如果您真的想要类似按钮的样式,您可以利用将HTML放入单元格的功能。
data = {'a', '1', '<html><input type="submit" value="Click Me"/></html>';
'b', '2', '<html><input type="submit" value="Click Me"/></html>'};
使用'html'标签很好的解决方法。它不会很好地调整大小,但它的确有诀窍......并且不需要任何java黑客攻击。 – Hoki
[This answer](http://stackoverflow.com/a/11263140/4806927)可能对你有帮助。 –