フィルターのクリア

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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by