Prev: Accessing hardware and DLLs in MatLab
Next: Smooting
From: Adam on 18 Jun 2010 17:59 Thanks, I figured there is no high-level way to do it. What I'm doing now, is using the Cell Selection Callback to find the index of the cell. Then I set the index to a handle. As shown below: 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.
From: Yair Altman on 19 Jun 2010 17:42 "Adam " <abc5(a)ubc.ca> wrote in message ... > 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
From: Yair Altman on 19 Jun 2010 18:05 "Yair Altman" <altmanyDEL(a)gmailDEL.comDEL> wrote in message <hvjdjd$69o$1(a)fred.mathworks.com>... > "Adam " <abc5(a)ubc.ca> wrote in message ... > > 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
From: Richard Xiong on 24 Jun 2010 13:57
jscroll = findjobj(t); jtable = jscroll.getViewport.getComponent(0); The value is stored in get(jtable.getEditorComponent,'text'). when hit the button I use the stored value to replace the value read from data=get(table,'Data'). Richard "Adam " <abc5(a)ubc.ca> wrote in message <hvgi36$od5$1(a)fred.mathworks.com>... > Hi, > > 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 |