uicheckbox
Create check box component
Description
creates a check box in
a new figure window and returns the cbx
= uicheckboxCheckBox
object. MATLAB® calls the uifigure
function to create the
figure.
specifies cbx
= uicheckbox(___,Name,Value
)CheckBox
properties using one or more
Name,Value
pair arguments. Use this option with any of the
input argument combinations in the previous syntaxes.
Examples
Create Check Box
Create a check box.
fig = uifigure; cbx = uicheckbox(fig);
Create Check Box Within a Panel
Create a panel. Then create a check box within the panel.
fig = uifigure; pnl = uipanel(fig); cbx = uicheckbox(pnl);
Set and Access Check Box Property Values
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
Code Response to Check Box Selection
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 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.
Input Arguments
parent
— Parent container
Figure
object (default) | Tab
object | Panel
object | ButtonGroup
object | GridLayout
object
Parent container, specified as a Figure
object created using the uifigure
function or one of its child
containers: Tab
, Panel
, ButtonGroup
, or GridLayout
. If you do not specify a parent container, MATLAB calls the uifigure
function to create a new Figure
object that serves as the parent container.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
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.
Value
— State of check box
0 (default) | 1
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.
ValueChangedFcn
— Value changed callback
[]
(default) | function handle | cell array | character vector
Value changed callback, specified as one of these values:
A function handle.
A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.
A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.
This callback executes when the user selects or clears the check box in the app. The callback does not execute if the check box value changes programmatically.
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.
Property | Value |
---|---|
Value | Value of check box after most recent app user interaction with it. |
PreviousValue | Value of check box before most recent app user interaction with it. |
Source | Component that executes the callback. |
EventName | 'ValueChanged' |
For more information about writing callbacks, see Callbacks in App Designer.
Position
— Location and size of check box
[100 100 84 22]
(default) | [left bottom width height]
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.
Element | Description |
---|---|
left | Distance from the inner left edge of the parent container to the outer left edge of the check box |
bottom | Distance from the inner bottom edge of the parent container to the outer bottom edge of the check box |
width | Distance between the right and left outer edges of the check box |
height | Distance 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]
Version History
Introduced in R2016aR2020b: Wrap check box text
Use the WordWrap
property to prevent text from getting
clipped horizontally when the width of the UI component is smaller than the text you
want to display. Setting the WordWrap
property to
'on'
breaks the text into new lines so that each line fits
within the component. It avoids breaking words when possible. When the property is
set to 'off'
, the text does not wrap.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)