Creating a Checkbox depending on another Checkbox [GUI]

4 次查看(过去 30 天)
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!

回答(1 个)

Geoff Hayes
Geoff Hayes 2016-8-13
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.

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by