|
|
row-wise selection in a uitable
I'm developing a matlab gui using R2010b. The gui has a uitable. By following the hints here (http://www.mathworks.com/matlabcentral/newsreader/view_thread/268448#702699) I have made clicks on the uitable select an entire row.
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
|
|
0
|
|
|
|
Reply
|
Adam
|
2/3/2011 11:54:04 PM |
|
Hi all,
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
|
|
0
|
|
|
|
Reply
|
Adam
|
2/23/2011 3:49:04 AM
|
|
Thanks. This came in really handy for me!
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 " <adam@noneedforspam.abc> wrote in message <ik203g$nql$1@fred.mathworks.com>...
> Hi all,
>
> 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
|
|
0
|
|
|
|
Reply
|
coffee_pot
|
3/23/2011 2:08:04 AM
|
|
|
2 Replies
556 Views
(page loaded in 0.023 seconds)
|
|
|
|
|
|
|
|
|