0

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

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
Leo
  • 11
  • 5

1 Answers1

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