ButtonGrid with properties:
+.S12 { margin: 15px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: 700; text-align: left; }
Widgets Toolbox - MATLAB App Designer Components - Examples
Widgets Toolbox helps you efficiently develop advanced user interfaces in MATLAB and App Designer. Widgets combine existing control functionalities together into larger, reusable, common functionality to accelerate development of graphical user interfaces.
Copyright 2020-2022 The MathWorks, Inc.
Button Grid
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 75]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
buttonGridWidget = wt.ButtonGrid(gridObj);
buttonGridWidget.BackgroundColor = [.6 .8 1];
buttonGridWidget.Icon = [
buttonGridWidget.Text = [
buttonGridWidget.Tooltip = [
buttonGridWidget.ButtonPushedFcn = @(src,evt)disp(evt)
buttonGridWidget =
ButtonGrid with properties:
Icon: ["add_24.png" "delete_24.png" "play_24.png" "pause_24.png" "stop_24.png"]
Text: ["Add" "Delete" "Play" "Pause" "Stop"]
@@ -50,7 +50,7 @@
Position: [11 11 230 55]
Show all properties
-
Checkbox List
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 200]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
cbListWidget = wt.CheckboxList(gridObj);
cbListWidget.Value(3) = false;
% This is optional (default is false)
cbListWidget.ShowSelectAll = true;
cbListWidget.ValueChangedFcn = @(src,evt)disp(evt)
cbListWidget =
CheckboxList with properties:
+
Checkbox List
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 200]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
cbListWidget = wt.CheckboxList(gridObj);
cbListWidget.Value(3) = false;
% This is optional (default is false)
cbListWidget.ShowSelectAll = true;
cbListWidget.ValueChangedFcn = @(src,evt)disp(evt)
cbListWidget =
CheckboxList with properties:
Items: [7×1 string]
Value: [7×1 logical]
@@ -59,7 +59,7 @@
Position: [11 11 230 180]
Show all properties
-
Color Selector
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 45]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
colorWidget = wt.ColorSelector(gridObj);
colorWidget.Value = [1 0 0];
colorWidget.ValueChangedFcn = @(src,evt)disp(evt)
colorWidget =
ColorSelector with properties:
+
Color Selector
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 45]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
colorWidget = wt.ColorSelector(gridObj);
colorWidget.Value = [1 0 0];
colorWidget.ValueChangedFcn = @(src,evt)disp(evt)
colorWidget =
ColorSelector with properties:
Value: [1 0 0]
ShowEditField: on
@@ -67,13 +67,13 @@
Position: [100 100 100 100]
Show all properties
-
If you want to have only the button with no edit field:
colorWidget.Value = [0 1 0];
% Turn off the edit field
colorWidget.ShowEditField = false;
% Make it a sensible width
gridObj.ColumnWidth = {27}
gridObj =
GridLayout with properties:
+
If you want to have only the button with no edit field:
colorWidget.Value = [0 1 0];
% Turn off the edit field
colorWidget.ShowEditField = false;
% Make it a sensible width
gridObj.ColumnWidth = {27}
gridObj =
GridLayout with properties:
RowHeight: {'1x'}
ColumnWidth: {[27]}
Show all properties
-
Datetime Selector
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 350 45]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
dateWidget = wt.DatetimeSelector(gridObj)
dateWidget =
DatetimeSelector with properties:
+
Datetime Selector
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 350 45]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
dateWidget = wt.DatetimeSelector(gridObj)
dateWidget =
DatetimeSelector with properties:
Value: 08-Apr-2022 12:00 AM
ShowAMPM: on
@@ -86,7 +86,7 @@
Position: [100 100 100 100]
Show all properties
-
If you want to configure the widget differently:
dateWidget.DateFormat = "MM/dd/uuuu";
dateWidget.DisabledDaysOfWeek = ["Saturday" "Sunday"];
dateWidget.Value = datetime("now","TimeZone","local");
dateWidget.ShowSeconds = "on";
dateWidget.ShowAMPM = "off";
File Selector
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 45]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
fileWidget = wt.FileSelector(gridObj);
fileWidget.Value = matlabroot;
fileWidget.ValueChangedFcn = @(src,evt)disp(evt)
fileWidget =
FileSelector with properties:
+
If you want to configure the widget differently:
dateWidget.DateFormat = "MM/dd/uuuu";
dateWidget.DisabledDaysOfWeek = ["Saturday" "Sunday"];
dateWidget.Value = datetime("now","TimeZone","local");
dateWidget.ShowSeconds = "on";
dateWidget.ShowAMPM = "off";
File Selector
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 45]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
fileWidget = wt.FileSelector(gridObj);
fileWidget.Value = matlabroot;
fileWidget.ValueChangedFcn = @(src,evt)disp(evt)
fileWidget =
FileSelector with properties:
Value: "C:\Program Files\MATLAB\R2022a"
FullPath: "C:\Program Files\MATLAB\R2022a"
@@ -100,7 +100,7 @@
Position: [100 100 100 100]
Show all properties
-
If you want to have a dropdown button to show recent history:
fileWidget.ShowHistory = true;
List Selector (single pane)
The List Selector widget is intended for adding items to a list from a known set. You can optionally enable reordering the items, and add custom buttons.
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 215]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
listWidget = wt.ListSelector(gridObj);
listWidget.Items = ["California","Massachusetts","Michigan","Texas"];
listWidget.Value = ["Massachusetts","Michigan"];
listWidget.ValueChangedFcn = @(src,evt)disp(evt)
listWidget =
ListSelector with properties:
+
If you want to have a dropdown button to show recent history:
fileWidget.ShowHistory = true;
List Selector (single pane)
The List Selector widget is intended for adding items to a list from a known set. You can optionally enable reordering the items, and add custom buttons.
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 215]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
listWidget = wt.ListSelector(gridObj);
listWidget.Items = ["California","Massachusetts","Michigan","Texas"];
listWidget.Value = ["Massachusetts","Michigan"];
listWidget.ValueChangedFcn = @(src,evt)disp(evt)
listWidget =
ListSelector with properties:
Items: ["California" "Massachusetts" "Michigan" "Texas"]
ItemsData: [1×0 double]
@@ -117,7 +117,7 @@
Position: [100 100 100 100]
Show all properties
-
You can also add your own custom buttons:
listWidget.UserButtons.Icon = ["plot_24.png","play_24.png"];
listWidget.UserButtons.ButtonHeight = {25 25};
listWidget.ButtonPushedFcn = @(src,evt)disp(evt);
List Selector Two Pane
The List Selector Two-Pane widget is similar to the one-pane variant. It is intended for adding items to a list from a known set. In this case, the set of available items is displayed in a list on the left side, and items are selectively added to the right list.
Again you can optionally enable reordering the items and add custom buttons.
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 300 215]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
listWidget2 = wt.ListSelectorTwoPane(gridObj);
listWidget2.Items = ["California","Massachusetts","Michigan","Texas"];
listWidget2.Value = ["Massachusetts","Michigan"];
Password Field
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 45]);
gridObj = uigridlayout(figObj,[1 2],"BackgroundColor",[.6 .8 1]);
gridObj.ColumnWidth = {'fit','1x'};
uilabel(gridObj,"Text","Password:");
This component won't show in the preview, but it will create a password field with text displayed as dots.
passwordWidget = wt.PasswordField(gridObj);
passwordWidget.Value = "MathWorks";
Progress Bar
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 300 60]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
progressWidget = wt.ProgressBar(gridObj);
progressWidget.ShowCancel = true;
progressWidget.CancelPressedFcn = @(h,e)disp("Cancel Pressed!")
progressWidget =
ProgressBar with properties:
+
You can also add your own custom buttons:
listWidget.UserButtons.Icon = ["plot_24.png","play_24.png"];
listWidget.UserButtons.ButtonHeight = {25 25};
listWidget.ButtonPushedFcn = @(src,evt)disp(evt);
List Selector Two Pane
The List Selector Two-Pane widget is similar to the one-pane variant. It is intended for adding items to a list from a known set. In this case, the set of available items is displayed in a list on the left side, and items are selectively added to the right list.
Again you can optionally enable reordering the items and add custom buttons.
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 300 215]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
listWidget2 = wt.ListSelectorTwoPane(gridObj);
listWidget2.Items = ["California","Massachusetts","Michigan","Texas"];
listWidget2.Value = ["Massachusetts","Michigan"];
Password Field
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 45]);
gridObj = uigridlayout(figObj,[1 2],"BackgroundColor",[.6 .8 1]);
gridObj.ColumnWidth = {'fit','1x'};
uilabel(gridObj,"Text","Password:");
This component won't show in the preview, but it will create a password field with text displayed as dots.
passwordWidget = wt.PasswordField(gridObj);
passwordWidget.Value = "MathWorks";
Progress Bar
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 300 60]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
progressWidget = wt.ProgressBar(gridObj);
progressWidget.ShowCancel = true;
progressWidget.CancelPressedFcn = @(h,e)disp("Cancel Pressed!")
progressWidget =
ProgressBar with properties:
ShowTimeRemaining: on
ShowCancel: on
@@ -134,7 +134,7 @@
Position: [100 100 100 100]
Show all properties
-
progressWidget.startProgress("The task is starting...");
% Wait some time to simulate a running task
% Update the task progress
progressWidget.setProgress(0.5, "The task is running...");
Then, when the task is done:
progressWidget.finishProgress("The task is finished");
If you want an indeteriminate progress bar:
progressWidget.Indeterminate = true;
progressWidget.startProgress("The task is running...");
Slider Checkbox Combination Group
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 125]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
sliderCheckboxWidget = wt.SliderCheckboxGroup(gridObj);
sliderCheckboxWidget.Name = ["Red", "Green", "Blue", "Alpha"];
sliderCheckboxWidget.CheckboxWidth = 100
sliderCheckboxWidget =
SliderCheckboxGroup with properties:
+
progressWidget.startProgress("The task is starting...");
% Wait some time to simulate a running task
% Update the task progress
progressWidget.setProgress(0.5, "The task is running...");
Then, when the task is done:
progressWidget.finishProgress("The task is finished");
If you want an indeteriminate progress bar:
progressWidget.Indeterminate = true;
progressWidget.startProgress("The task is running...");
Slider Checkbox Combination Group
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 125]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
sliderCheckboxWidget = wt.SliderCheckboxGroup(gridObj);
sliderCheckboxWidget.Name = ["Red", "Green", "Blue", "Alpha"];
sliderCheckboxWidget.CheckboxWidth = 100
sliderCheckboxWidget =
SliderCheckboxGroup with properties:
Name: ["Red" "Green" "Blue" "Alpha"]
State: [1 1 1 1]
@@ -145,7 +145,7 @@
Position: [100 100 100 100]
Show all properties
-
sliderCheckboxWidget.Value = [0.8, 0.3, 0, 1];
sliderCheckboxWidget.State = [true, true, false, true];
sliderCheckboxWidget.ValueChangedFcn = @(src,evt)disp(evt)
sliderCheckboxWidget =
SliderCheckboxGroup with properties:
+
sliderCheckboxWidget.Value = [0.8, 0.3, 0, 1];
sliderCheckboxWidget.State = [true, true, false, true];
sliderCheckboxWidget.ValueChangedFcn = @(src,evt)disp(evt)
sliderCheckboxWidget =
SliderCheckboxGroup with properties:
Name: ["Red" "Green" "Blue" "Alpha"]
State: [1 1 0 1]
@@ -156,7 +156,7 @@
Position: [11 11 230 105]
Show all properties
-
Slider Spinner Combination
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 70]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
sliderSpinnerWidget = wt.SliderSpinner(gridObj);
sliderSpinnerWidget.Limits = [-10 30];
sliderSpinnerWidget.RoundFractionalValues = "off";
sliderSpinnerWidget.Step = 0.5;
sliderSpinnerWidget.Value = 16.5;
sliderSpinnerWidget.ValueChangedFcn = @(src,evt)disp(evt)
sliderSpinnerWidget =
SliderSpinner with properties:
+
Slider Spinner Combination
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 70]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
sliderSpinnerWidget = wt.SliderSpinner(gridObj);
sliderSpinnerWidget.Limits = [-10 30];
sliderSpinnerWidget.RoundFractionalValues = "off";
sliderSpinnerWidget.Step = 0.5;
sliderSpinnerWidget.Value = 16.5;
sliderSpinnerWidget.ValueChangedFcn = @(src,evt)disp(evt)
sliderSpinnerWidget =
SliderSpinner with properties:
Value: 16.5
Limits: [-10 30]
@@ -177,7 +177,7 @@
Position: [11 11 230 50]
Show all properties
-
Task Status Table
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 225]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
taskStatusWidget = wt.TaskStatusTable(gridObj);
taskStatusWidget.Items = [
taskStatusWidget.Status = [
taskStatusWidget.SelectedIndex = 3;
taskStatusWidget.ButtonPushedFcn = @(src,evt)disp(evt)
taskStatusWidget =
TaskStatusTable with properties:
+
Task Status Table
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 250 225]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
taskStatusWidget = wt.TaskStatusTable(gridObj);
taskStatusWidget.Items = [
taskStatusWidget.Status = [
taskStatusWidget.SelectedIndex = 3;
taskStatusWidget.ButtonPushedFcn = @(src,evt)disp(evt)
taskStatusWidget =
TaskStatusTable with properties:
Items: [5×1 string]
Status: [5×1 wt.enum.StatusState]
@@ -192,7 +192,7 @@
Position: [11 11 230 205]
Show all properties
-
Toolbar
Horizontal Sections
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 350 120]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
toolbarWidget1 = wt.Toolbar(gridObj);
% Create a horizontal section
section1 = wt.toolbar.HorizontalSection();
section1.Title = "NORMAL BUTTONS";
section1.addButton("open_24.png", "Open");
section1.addButton("save_24.png", "Save");
% Create a horizontal section with state buttons
section2 = wt.toolbar.HorizontalSection();
section2.Title = "STATE BUTTONS";
stateButton1 = section2.addStateButton("","Mode 1");
stateButton2 = section2.addStateButton("","Mode 2");
stateButton3 = section2.addStateButton("","Mode 3");
% Set the state of the buttons
stateButton1.Value = true;
stateButton2.Value = false;
stateButton3.Value = false;
% Attach the horizontal sections to the toolbar
toolbarWidget1.Section = [
toolbarWidget1.ButtonPushedFcn = @(src,evt)disp(evt)
toolbarWidget1 =
Toolbar with properties:
+
Toolbar
Horizontal Sections
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 350 120]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
toolbarWidget1 = wt.Toolbar(gridObj);
% Create a horizontal section
section1 = wt.toolbar.HorizontalSection();
section1.Title = "NORMAL BUTTONS";
section1.addButton("open_24.png", "Open");
section1.addButton("save_24.png", "Save");
% Create a horizontal section with state buttons
section2 = wt.toolbar.HorizontalSection();
section2.Title = "STATE BUTTONS";
stateButton1 = section2.addStateButton("","Mode 1");
stateButton2 = section2.addStateButton("","Mode 2");
stateButton3 = section2.addStateButton("","Mode 3");
% Set the state of the buttons
stateButton1.Value = true;
stateButton2.Value = false;
stateButton3.Value = false;
% Attach the horizontal sections to the toolbar
toolbarWidget1.Section = [
toolbarWidget1.ButtonPushedFcn = @(src,evt)disp(evt)
toolbarWidget1 =
Toolbar with properties:
Section: [2×1 HorizontalSection]
DividerColor: [0.94 0.94 0.94]
@@ -200,7 +200,7 @@
Position: [100 100 100 100]
Show all properties
-
Toolbar
Vertical sections
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 375 130]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
toolbarWidget2 = wt.Toolbar(gridObj);
% Create a horizontal section with vertical subsection
section3 = wt.toolbar.HorizontalSection();
section3.Title = "MIXED HORIZONTAL / VERTICAL";
section3.addButton("left_24.png","");
section3.addButton("right_24.png","");
% Create the vertical subsection
section3v1 = section3.addVerticalSection();
section3v1.addButton("play_24.png","Play");
section3v1.addButton("stop_24.png","Stop");
% Add a manual component to the vertical section
sliderObj = uislider("Parent",[]);
section3v1.Component(end+1) = sliderObj;
% Attach a callback to the slider
% This is required for manually adding components
sliderObj.ValueChangedFcn = @(src,evt)disp(evt);
% Create more horizontal items
section3.addButton("pause_24.png","Pause");
% Add another basic section
section4 = wt.toolbar.HorizontalSection();
section4.addButton('help_24.png','Help');
% Attach the horizontal sections to the toolbar
toolbarWidget2.Section = [
toolbarWidget2.ButtonPushedFcn = @(src,evt)disp(evt)
toolbarWidget2 =
Toolbar with properties:
+
Toolbar
Vertical sections
% Create a figure with a grid layout
figObj = uifigure("Position",[100 100 375 130]);
gridObj = uigridlayout(figObj,[1 1],"BackgroundColor",[.6 .8 1]);
toolbarWidget2 = wt.Toolbar(gridObj);
% Create a horizontal section with vertical subsection
section3 = wt.toolbar.HorizontalSection();
section3.Title = "MIXED HORIZONTAL / VERTICAL";
section3.addButton("left_24.png","");
section3.addButton("right_24.png","");
% Create the vertical subsection
section3v1 = section3.addVerticalSection();
section3v1.addButton("play_24.png","Play");
section3v1.addButton("stop_24.png","Stop");
% Add a manual component to the vertical section
sliderObj = uislider("Parent",[]);
section3v1.Component(end+1) = sliderObj;
% Attach a callback to the slider
% This is required for manually adding components
sliderObj.ValueChangedFcn = @(src,evt)disp(evt);
% Create more horizontal items
section3.addButton("pause_24.png","Pause");
% Add another basic section
section4 = wt.toolbar.HorizontalSection();
section4.addButton('help_24.png','Help');
% Attach the horizontal sections to the toolbar
toolbarWidget2.Section = [
toolbarWidget2.ButtonPushedFcn = @(src,evt)disp(evt)
toolbarWidget2 =
Toolbar with properties:
Section: [2×1 HorizontalSection]
DividerColor: [0.94 0.94 0.94]