Creating a Checkbox depending on another Checkbox [GUI]

3 vues (au cours des 30 derniers jours)
mec123
mec123 le 11 Août 2016
Hi,
i have to checkboxes. Since the second checkbox activates an additional action to the first checkbox, it must not be "clickable" until the first checkbox is checked.
-> only two possible scenarios: first checked, or both checked.
Is that possible?
I dont think its necessary, but to be more specific:
The first checkbox creates a 3d plot, and the second one creates and saves an adequate fig-file.
Thanks a lot for helping!

Réponses (1)

Geoff Hayes
Geoff Hayes le 13 Août 2016
mec123 - suppose that you have two checkboxes, checkbox1 and checkbox2, with the latter being enabled only if checkbox1 is checked. To disable the second one, in the OpeningFcn of your GUI you would do
function myGui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
set(handles.checkbox2,'Enable','off');
Then in the callback for your first checkbox, you would do
function checkbox1_Callback(hObject, eventdata, handles)
if get(hObject,'Value') == 1
set(handles.checkbox2,'Enable','on');
else
set(handles.checkbox2,'Value',0,'Enable','off');
end
If checkbox1 is checked (and so its Value property is set to one) then we enable the other checkbox. Else if checkbox1 is unchecked (and so its Value property is set to zero) then we clear the checked state of checkbox2 and disable it.

Community Treasure Hunt

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

Start Hunting!

Translated by