MATLAB: Change the font of a text edit box using checkbox in gui

change fontcheckboxfontguitext edit

Hi, I would like to know if there is a way of changing the font of an inserted text by clicking on a checkbox.

Best Answer

You can assign a callback to the checkbox that will change the FontSize property of the text.
Example:
f= figure
txt = uicontrol('Style','text',...
'String','hello','Tag','txt1') %text object with tag 'txt1'
check_box = uicontrol('Style','checkbox',...
'callback',@edit_txt) %checking the box triggers callback function 'edit_txt'
Now you can define the callback as:
function edit_txt(Obj_handle, event)
t = findobj(gcf,'Tag','txt1') % this will be your text object.
if Obj_handle.Value == 0 % if unchecked. Note: Obj_handle is the handle to the chkbox
t.FontSize = 8;
else %if checked
t.FontSize = 30;
end
end
Related Question