I'm making a GUI that takes in input via a table. As the user, you would add data then click start to run the algorithm using the data from the table. My issue is that the Data in a cell is not updated until the user actually moves away from the cell. Is there a way to have the data update upon the value being changed. The table's callback also only runs once the user have moved away from the cell.
The problem is say the user changes the value in cell 1 from '3' to '5', then immediately clicks on the start button (without clicking somewhere else first). When I retrieve from the cell the value is still '3'. Is there a work around this? Perhaps, some way to force a update on the cell data.
Thanks a lot,
Adam
one of the solutions as a skeleton
uh=uitable;
set(uh,...
'data',magic(2),...
'columneditable',true,...
'celleditcallback','get(uh,''data'')');
% now change values and move the focus away from the cell...
% eg, TAB, mouse click, etc...
us
Thanks us, that is basicly what I have now.
What I have:
set(handles.inputTable,...
'BackgroundColor',[0.93 0.93 0.93
0.7 0.9 0.9 ],...
'Units','normalized',...
'Data',dat,...
'Enable','on',...
'RowName',rownames,...
'CellEditCallback',@inputTable_Callback,...
'ColumnWidth', columnwidth,...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', columneditable);
function inputTable_Callback(source, eventdata)
data=get(source,'Data')
numericCheck(data{eventdata.Indices(1),eventdata.Indices(2)})
end
This doesn't work since 'Data' is not changed upon keystroke, but rather when the user moves focus away from the cell.
> The problem is say the user changes the value in cell 1 from '3' to '5',
> then immediately clicks on the start button (without clicking somewhere
> else first). When I retrieve from the cell the value is still '3'. Is
> there a work around this? Perhaps, some way to force a update on the
> cell data.
It's a known limitation in all kinds of edit fields. I don't know what the
technical limitation *is*, but I gather it is considered to not be fixable.
The work-around is to use key press callbacks and to handle each key press
independently, including things like handling the pressing of backspace as
meaning you want to correct the previous character. This approach has some
difficulties as well.
My memory is a bit fuzzy at the moment (too much hot chocolate); I seem to
recall that to do the key press callbacks for a uitable that you might have to
go in at the java level. If so then the technique will be described in more
detail at http://undocumented-matlab.com
function inputTable_CellSelectionCallback(source, eventdata)
handles=guidata(source);
handles.currentCell=eventdata.Indices
guidata(gcf,handles)
end
Then I use this index in the KeyPressFcn to manually store the data on keypress.
function inputTable_KeyPressFcn(source, eventdata)
handles=guidata(gcf);
Indices=handles.currentCell;
data=get(source,'Data');
data{Indices(1),Indices(2)}=str2double(eventdata.Key)
set(handles.inputTable,'Data',data);
end
This seems to work if only one number is inputed. However if we go to double digits, the last one gets removed. I could concatenate what's already in the cell with the new key, but as you mentioned, backspace/arrows etc. will also have to be manually programmed. I don't think other coders will like that. Addtionally, the set command causes the cell to lose focus, making cellselection give an error.
I guess I'll switch back to edit boxes or something. Thanks for the help though. Now I know it can't be done.
This is an intolerable snide on Java components :-)
Of course it can be done - you just need to get the relevant Java component (for example, using the FindJObj utility on the File Exchange) and then set its FocusLostCallback to trigger an editting-stop action:
mtable = uitable(...);
jscroll = findjobj(mtable);
jtable = jscroll.getViewport.getComponent(0);
hjtable = handle(jtable,'CallbackProperties');
set(hjtable, 'FocusLostCallback', @myCallbackFunc);
function myCallbackFunc(jtable,eventdata)
component = jtable.getEditorComponent;
if ~isempty(component)
event = javax.swing.event.ChangeEvent(component);
jtable.editingStopped(event);
end
end
Yair Altman
http://UndocumentedMatlab.com
Or an even simpler hack (see related: http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4709394 ):
jtable.putClientProperty('terminateEditOnFocusLost', true);
Yair
Richard
"Adam " <ab...@ubc.ca> wrote in message <hvgi36$od5$1...@fred.mathworks.com>...