Matlab uitable data selection

与世无争的帅哥 提交于 2019-12-06 13:57:27

You should edit the CellSelectionCallback and the CellEditCallback properties of your table.

   set(myTable,`CellSelectionCallback`,@CallBack)

In order to see what columns/rows were selected, use the event data that you receive in your callback.

  function CallBack(hObj,evt)   
      disp(evt);
  end

As far as I know, there is no way to discover what columns are currently selected when the callback is not fired.

To handle clicks on the column headers, one must go to undocumented territory:

%# old UITABLE (based on Swing JTable, instead of the new JIDE-based)
[hTable,hContainer] = uitable('v0', 'Parent',gcf, ...
    'Data',magic(7), 'ColumnNames',cellstr(num2str((1:7)','C%d'))');
set(hContainer, 'Units','normalized', 'Position',[0 0 1 1])

%# handle mouse clicks on table headers
jTableHeader = hTable.getTable().getTableHeader();
h = handle(jTableHeader, 'CallbackProperties');
set(h, 'MousePressedCallback',...
    @(src,evt) disp( src.columnAtPoint(evt.getPoint())+1 ))  %# zero-based index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!