Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

uicheckbox

(App Designer) Create check box component

Use only with App Designer or figures created with the uifigure function. When using GUIDE or the figure function, create a check box using uicontrol.

Syntax

cbx = uicheckbox
cbx = uicheckbox(parent)
cbx = uicheckbox(___,Name,Value)

Description

cbx = uicheckbox creates a check box in a new UI figure window and returns the CheckBox object.

example

cbx = uicheckbox(parent) creates the check box in the specified parent container. The parent container can be a Figure created using the uifigure function, or one of its child containers: Tab, Panel, or ButtonGroup.

example

cbx = uicheckbox(___,Name,Value) specifies CheckBox properties using one or more Name,Value pair arguments. Use this option with any of the input argument combinations in the previous syntaxes.

Input Arguments

collapse all

Parent object, specified as a Figure created using the uifigure function, or one of its child containers: Tab, Panel, or ButtonGroup.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Value',1 specifies that the check box is displayed with a check mark.

The properties listed here are a subset of the available properties. For the full list, see CheckBox Properties.

collapse all

State of the check box, specified as 0 (false) or 1 (true). When the Value property is set to 1, the check box is checked. When the Value property is set to 0, the check box is not checked.

Code to execute when the app user selects or clears the check box, specified as one of these values:

  • Function handle

  • Cell array containing a function handle and additional arguments

  • Character vector that is a valid MATLAB® expression, which is evaluated in the base workspace.

This callback function can access specific information about the user’s interaction with the check box. MATLAB passes this information in a ValueChangedData object as the second argument to your callback function. In App Designer, the argument is called event. You can query the object properties using dot notation. For example, event.PreviousValue returns the previous value of the check box. The ValueChangedData object is not available to callback functions specified as character vectors.

The following table lists the properties of the ValueChangedData object.

PropertyValue
ValueValue of check box after most recent app user interaction with it.
PreviousValueValue of check box before most recent app user interaction with it.
SourceComponent that executes the callback.
EventName'ValueChanged'

The ValueChangedFcn callback does not execute if the check box value changes programmatically.

Location and size of the check box relative to the parent, specified as the vector [left bottom width height]. This table describes each element in the vector.

ElementDescription
leftDistance from the inner left edge of the parent container to the outer left edge of the check box
bottomDistance from the inner bottom edge of the parent container to the outer bottom edge of the check box
widthDistance between the right and left outer edges of the check box
heightDistance between the top and bottom outer edges of the check box

The Position values are relative to the drawable area of the parent container. The drawable area is the area inside the borders of the container and does not include the area occupied by decorations such as a menu bar or title.

All measurements are in pixel units.

Example: [200 200 102 15]

Examples

collapse all

Create a check box.

fig = uifigure;
cbx = uicheckbox(fig);

Create a panel. Then create a check box within the panel.

fig = uifigure;
pnl = uipanel(fig);
cbx = uicheckbox(pnl);

Create a check box and specify property values.

fig = uifigure;
cbx = uicheckbox(fig, 'Text','Show Value',...
                  'Value', 1,...
                  'Position',[150 50 102 15]);

Clear the check box.

cbx.Value = 0;

Determine the font size of the check box text.

fsize = cbx.FontSize
fsize =

    12

Create a radio button group and a check box. When an app user selects the check box, a radio button is disabled.

Save the following code to disableRadioButton.m on your MATLAB path.

This code creates a window containing a radio button group and a check box. When an app user clears the check box, the check box ValueChangedFcn disables the third radio button.

function disableRadioButton
% Create a UI figure window:
fig = uifigure('Position',[100 100 229 276]);

% Create a button group and radio buttons:
bg = uibuttongroup('Parent',fig,...
    'Position',[56 77 123 85]);
rb1 = uiradiobutton(bg,'Position',[10 60 91 15]);
rb2 = uiradiobutton(bg,'Position',[10 38 91 15]);
rb3 = uiradiobutton(bg,'Position',[10 16 91 15]);

% Create a check box:
cbx = uicheckbox(fig,'Position',[55 217 102 15],...
    'ValueChangedFcn',@(cbx,event) cBoxChanged(cbx,rb3));
end

% Create the function for the ValueChangedFcn callback:
function cBoxChanged(cbx,rb3)
val = cbx.Value;
if val
    rb3.Enable = 'off';
else
    rb3.Enable = 'on';
end
end

Run disableRadioButton, and then select the check box. The third radio button is disabled.

See Also

Functions

Properties

Introduced in R2016a

Was this topic helpful?