필터 지우기
필터 지우기

Add CallbackFcn to checkbox jList

조회 수: 3 (최근 30일)
Florian Bastiaens
Florian Bastiaens 2015년 5월 13일
댓글: Walter Roberson 2015년 5월 16일
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?

답변 (1개)

Jan
Jan 2015년 5월 13일
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
Florian Bastiaens
Florian Bastiaens 2015년 5월 16일
Thanks for your respons Jan.
You were right, I tried creating the function inside the script and after I fixed that I still couldn't figure it out. So I tried a different approach.
I created a button under the chechboxes and pressing this button runs a script. This script checks what boxes are checked and plots the data corresponding to the boxes. All parts work independent of eachother but not together. The problem is running the script when pressing the button. I get the error:
Attempt to add "plotting" to a static workspace.
How do I fix this? I can't make a script global.
Walter Roberson
Walter Roberson 2015년 5월 16일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by