Comments on: Tri-state checkbox https://undocumentedmatlab.com/blog_old/tri-state-checkbox Charting Matlab's unsupported hidden underbelly Thu, 02 May 2024 08:00:01 +0000 hourly 1 https://wordpress.org/?v=4.4.1 By: Dhanya Pradeephttps://undocumentedmatlab.com/blog_old/tri-state-checkbox#comment-369918 Mon, 15 Feb 2016 09:59:00 +0000 https://undocumentedmatlab.com/?p=2467#comment-369918 Hi Yair,
I’m trying to use the com.mathworks.mwswing.checkboxtree in my MATLAB application. I’m trying all sorts of methods for handling the actions on enabling and disabling the checkbox node. Unfortunately I’m not getting the right callback to be used for handling the action based on the toggling of the checkbox. Could you give me some hint on the solution.

Thanks,
Dhanya

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/tri-state-checkbox#comment-134169 Sun, 16 Dec 2012 17:56:35 +0000 https://undocumentedmatlab.com/?p=2467#comment-134169 @Pecus –

The possible com.mathworks.mwswing.checkboxtree.SelectionState values are: MIXED, NOT_SELECTED and SELECTED, which are pretty-much self-explanatory.

I assume that you are using GUIDE to create your GUI. In such a case, the *_OutputFcn() function is called after the entire GUI is created, immediately before the control is passed to the user. In this function, you have access to all handles. See this doc-page.

]]>
By: Pecushttps://undocumentedmatlab.com/blog_old/tri-state-checkbox#comment-134140 Sun, 16 Dec 2012 16:18:53 +0000 https://undocumentedmatlab.com/?p=2467#comment-134140 @Yair – Thanks for all the advice here! Just discovering all these mysteries…

I’m having difficulties (probably the same as weilang had) disabling the mixed state of JCheckBox. If it has not been in mixed state, then I can toggle its state and appeareance (selected or deselected) by clicking. But soon as I put it in mixed state, changing the state by clicking does not affect its appeareance.
Also I could not find the method for setting the state of JCheckBox to selected/deselected. For MWCheckbox it is “jCB.setSelected(1)” (or “0”).
To put it in a nutshell:
1. What is the opposite of “jCB.putClientProperty(‘selectionState’, SelectionState.MIXED);”?
2. What is the counterpart of “jCB.setSelected(1)”?

Third problem: I wrote a Callback function to switch on or off all subordinated checkboxes, if my JCheckBox has been clicked: (Still only works when not in mixed mode.)

function Tristatecheckbox_Callback(hObject,eventdata,subCBs) % subCBs as CELL
isSelected=hObject.isSelected;
n=size(subCBs);
for i=1:n(2)
   set(subCBs{i},'Value',isSelected);
end

Now my problem is where/when to associate this function with Java Callbacks.
I wrote this code snippet, which is working:

hjCB = handle(handles.jCB,'CallbackProperties'); % initialised with "handles.jCB = javax.swing.JCheckBox(..."
subCBs={handles.CB1,handles.CB2,handles.CB3};
set(hjCB,'ItemStateChangedCallback',{@Tristatecheckbox_Callback,subCBs});

First I put it right after the JCheckBox’s creation, which is in the CreateFcn of a panel. But in CreateFcns there are no visible handles but those of the object in creation, so handles.CB1 can not be allocated.
For trial&error, I put it in the CallbackFcn of a dummy pushbutton and just clicked this dummy before using the rest, but later I need this snippet to be done before the user can do anything with the GUI.
3. Is there a function running right after the GUI is created, with access to all the handles? Which one? And if no, where else to put the code?

Thanks a lot!

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/tri-state-checkbox#comment-62397 Sat, 19 Nov 2011 16:04:38 +0000 https://undocumentedmatlab.com/?p=2467#comment-62397 @weiliang – Java controls have some ~30 standard callbacks that you can set, ranging from mouse and keyboard events, through property and hierarchy changes, plus several callbacks that are specific to the control. Try setting the StateChangedCallback and ItemStateChangedCallback. More on Java component callbacks can be found here and in sections 3.4 and 6.4 of my Matlab-Java book.

]]>
By: weilianghttps://undocumentedmatlab.com/blog_old/tri-state-checkbox#comment-62288 Fri, 18 Nov 2011 19:20:36 +0000 https://undocumentedmatlab.com/?p=2467#comment-62288 I have tried all three approaches.
The first one, Modifying the standard Matlab checkbox uicontrol, has little change to my existing code, but the call to findjobj is too expansive and time consuming (i have more than 10 checkboxes).
Both Displaying as an independent Java control and Alternative controls will have no performance problem. but I have difficulty to add callbacks to the jCheckbox.
Also all three seem have drawing problem when is in third state (partial check state).
Can someone comment on this. Code sample for how to add callback to the last two methods is greatly appreciated.

]]>