The code to do this is below:
hJScroll = findjobj(handles.tblParamsets); % findjobj is from file exchange
hJTable = hJScroll.getViewport.getView; % get the table component within the scroll object
hJTable.setNonContiguousCellSelection(false);
hJTable.setColumnSelectionAllowed(false);
hJTable.setRowSelectionAllowed(true);
set(handles.tblParamsets, 'CellSelectionCallback', '...'); % from GUIDE
The problem I'm having is that once I turn on the non-contiguous cell selection property of the Java object, selecting rows in the uitable no longer triggers the cell selection callback. If I don't set this parameter to false, the cell selection callback still fires, but I can't constrain the user to select entire rows of the table.
Has anyone solved this problem in the past? If so, how?
Really all that I want to happen is (a) for the user to be able to select entire rows of the table, and, (b) have a callback that'll tell me which row was selected.
Thanks,
Adam
I figured this problem out myself a few weeks back but thought I'd share my solution just in case anyone else has the problem in the future.
I used one the callbacks defined for the JTable object as the matlab callback didn't seem to be triggering after I messed with the properties of the JTable object.
So I added something similar to this to my original code:
hJTable = handle(hJTable, 'CallbackProperties');
set(hJTable, 'MousePressedCallback', {@MyCellSelectionCallback, gcf});
...and then I defined my callback function...
function MyCellSelectionCallback(hObject, eventData, currFig)
% commands to so stuff on selection of a table row
I also used tips from this thread: http://www.mathworks.com/matlabcentral/newsreader/view_thread/165066
In particular, the 6th message which says:
"> Is there a way to tell what cells are currently selected?
mtable = uitable(gcf, magic(3), {'A', 'B', 'C'});
jtable = mtable.getTable;
row = jtable.getSelectedRow + 1; % Java indexes start at 0
col = jtable.getSelectedColumn + 1;
If multiple cells are selected, you might want to use
getSelectedRows and getSelectedColumns which return an array
of int32 indexes (0-based).
Yair"
"Adam " <ad...@noneedforspam.abc> wrote in message <ik203g$nql$1...@fred.mathworks.com>...