Add CallbackFcn to checkbox jList
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi everyone,
I managed to create a checkboxlist using the following code.
% First create the data model
jList = java.util.ArrayList; % any java.util.List will be ok
for i = 1:Nrofmsrmnts
jList.add(java.lang.String(Measurement(i).name));
end
% Next prepare a CheckBoxList component within a scroll-pane
jCBList = com.mathworks.mwswing.checkboxlist.CheckBoxList(jList);
jScrollPane = com.mathworks.mwswing.MJScrollPane(jCBList);
% Now place this scroll-pane within a Matlab container (figure or panel)
%[jhScroll,hContainer] = javacomponent(jScrollPane,[10,50,200,650],gcf);
% Update some items' state programmatically
jCBModel = jCBList.getCheckModel;
jCBModel.uncheckAll;
% Respond to checkbox update events
jhCBModel = handle(jCBModel, 'CallbackProperties');
set(jhCBModel, 'ValueChangedCallback', @myMatlabCallbackFcn);
Now I can check what checkboxes are checked using:
checked = jCBList.getCheckedIndicies
This works, but when I check a box I get the error:
Undefined function 'myMatlabCallbackFcn' for input arguments of type 'javahandle_withcallbacks.com.mathworks.mwswing.checkboxlist.DefaultListCheckModel'.
I tried using
function myMatlabCallbackFcn
but then I get this error: Function definitions are not permitted in this context.
How do I define this callback function?
0 comentarios
Respuestas (1)
Jan
el 13 de Mayo de 2015
Where did you try top create the function myMatlabCallbackFcn? You can define functions only inside function M-files, not inside scripts or inside the command window.
Teh callback gets an object of the type 'javahandle_withcallbacks.com.mathworks.mwswing.checkboxlist.DefaultListCheckModel'. Are you sure that your function can handle such an input?
2 comentarios
Walter Roberson
el 16 de Mayo de 2015
Assign a value to "plotting" before you make whatever call results in that error message. It doesn't matter what you assign, as long as it exists.
Ver también
Categorías
Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!