Is there a way to add a button in table cell in Matlab GUI so that each button can perform action depending on which row its in?
Asked
Active
Viewed 1,527 times
0
-
[This answer](http://stackoverflow.com/a/11263140/4806927) might be of help to you. – il_raffa Feb 21 '16 at 15:25
1 Answers
1
You can't do this without resorting to using java controls (something like this could get you going); however, you could setup a CellSelectionCallback
on the uitable
and determine what to execute based on the row.
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));
If you really want button-like styling you could exploit the ability to put HTML within your cells.
data = {'a', '1', '<html><input type="submit" value="Click Me"/></html>';
'b', '2', '<html><input type="submit" value="Click Me"/></html>'};

Suever
- 64,497
- 14
- 82
- 101
-
Nice workaround with the `html` tags. It doesn't resize beautifully but it does the trick ... and doesn't need any java hack. – Hoki Feb 22 '16 at 10:40