Reputation: 11
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?
Sample of What I am trying to make
Upvotes: 0
Views: 1693
Reputation: 65430
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>'};
Upvotes: 1