Pushbutton callback function reacts only after second press when cell in uitable was selected beforehand
Mostra commenti meno recenti
Hi,
I'm writing a switch rows function for a uitable which is started by a pushbutton in Matlab GUIDE. I've written the code which works fine though the problem is that I have to press the button twice as the corresponding callback function of the pushbutton is not started the first time.
I obviously need to select a cell in the table (I already got the indices via the cell selection callback function) and then press the pushbutton to do the actual switching. The callback function of the pushbutton should start immediately but it doesn't.
My Code is:
% --- Executes when selected cell(s) is changed in table_pathdata.
function table_pathdata_CellSelectionCallback(hObject, eventdata, handles)
% Read current cell indices
setappdata(hObject,'CurrentCell',eventdata.Indices);
Indices = getappdata(hObject,'CurrentCell');
assignin('base','Indices',Indices);
% --- Executes on button press in button_moverowup.
function button_moverowup_Callback(hObject, eventdata, handles)
'Teststring' % This String will only be displayed on second button press
% Switch code follows which is working fine (on second button press)
I hope someone can help with that problem. It might be very easy for experienced guys.
8 Commenti
Geoff Hayes
il 27 Ago 2014
Thomas - you may have to attach the complete code (m-file and fig-file) that may better illustrate the problem. Using the sample from above, I can select a cell in the table, and when I press the button, the 'TestString' immediately appears in the Command Window. This is with R2014a on a Mac.
As an aside, you do not have to save data as local variable in the base workspace. Just save the indices to the handles structure (using guidata) which the push button (and any other widget) will have easy access to. For example,
function table_pathdata_CellSelectionCallback(hObject, eventdata, handles)
% Read current cell indices
handles.selectedIndices = eventdata.Indices;
guidata(hObject,handles);
function button_moverowup_Callback(hObject, eventdata, handles)
% get the selected indices (if they exist)
if isfield(handles,'selectedIndices')
if ~isempty(handles.selectedIndices)
% do something with handles.selectedIndices
% finished with the selectedIndices so clear it
handles.selectedIndices = [];
guidata(hObject,handles);
end
end
The above is just a suggestion.
Thomas
il 28 Ago 2014
Geoff Hayes
il 28 Ago 2014
Hi Thomas - I can run your code, select a cell (so that it is all blue, not just the text), press the button and the cell contents (for each cell) changes to one. I do not have to press the button twice.
In the Command Window, check your java version
version -java
Mine (for R2014a on a Mac with OS X 10.8.5) is
Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
I'm not suggesting that you change versions (if yours is different) because that could be risky and I don't know what the repercussions would be. I'm just curious as to why I can run this example from the command line or through GUIDE and not have a problem.
I also checked this on a PC with R2014a and with the same version of java, and it worked fine - I could not reproduce the error. Same for R2013a with java 1.6.0_17-b04, again on the same PC.
What version of MATLAB are you using?
Thomas
il 28 Ago 2014
Geoff Hayes
il 28 Ago 2014
Modificato: Geoff Hayes
il 28 Ago 2014
The java version for my R2013a is no different than yours for your version of MATLAB. I think that Image Analyst has the best solution/amswer for this. Though why it works in my environment is beyond me..
Thomas
il 28 Ago 2014
Jeff Spector
il 9 Set 2014
I seem to be having this problem as well but I am using Java 1.6.0_65-b14-462-11M4609 with Apple Inc. Java HotSpot™ 64-Bit Server VM mixed mode
I have two different versions of my GUI the callback for a pushbutton is the same in both versions, but in one it works on the first click and in the other it takes two clicks..not sure why?
Risposte (1)
Image Analyst
il 27 Ago 2014
0 voti
I've seen this before. When my user enters some text into a cell of a uitable, and I want to do something in a pushbutton callback, the first push of the pushbutton doesn't do anything and they have to push/click the pushbutton a second time to do the callback of the push button. So I have to have the string of my pushbutton say "OK (Click twice when done)". I'm not sure what's going on but it's like the first click of the pushbutton merely steps editing of the uitable and changes focus from the table to the pushbutton, like it's just ending the editing session of the table or something. Sorry, I don't know of a fix but I'd like to.
Categorie
Scopri di più su Environment and Settings in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!