This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Create toggle button on toolbar


t = uitoggletool
t = uitoggletool(Name,Value,...)
t = uitoggletool(parent)
t = uitoggletool(parent,Name,Value,...)


t = uitoggletool creates a uitoggletool in the current figure’s uitoolbar and returns the uitoggletool object, t. If there is no uitoolbar available, then MATLAB® creates a new uitoolbar in the current figure to serve as the parent. Similarly, if there no figure is available, then MATLAB creates a new figure with a uitoolbar.

t = uitoggletool(Name,Value,...) creates a uitoggletool and specifies one or more uitoggletool property names and corresponding values. Use this syntax to override the default uitoggletool properties.

t = uitoggletool(parent) creates a uitoggletool and designates a specific parent object. The parent argument must be a uitoolbar object.

t = uitoggletool(parent,Name,Value,...) creates a uitoggletool with a specific parent and one or more uitoggletool properties.

A uitoggletool is a toggle button that appears in the figure’s tool bar. The button has no icon, but its borders highlight when the user hovers over it with the mouse. You can create a button icon by setting the uitoggletool’s CData property.


This example creates a uitoolbar and places a uitoggletool inside it.

f = figure('ToolBar','none');
tb = uitoolbar(f);
img = zeros(16,16,3);
t = uitoggletool(tb,'CData',img,'TooltipString','Hello');

The CData property is set to a 16-by-16-by-3 array in which all elements are 0. The zero values make the uitoggletool appear black.


  • Uitoolbars (and their child uitoggletools) do not appear in figures whose WindowStyle property is set to 'Modal'. If a figure containing a uitoolbar is changed to 'Modal', the uitoolbar still exists in the Children property of the figure. However, the uitoolbar does not display while WindowStyle is set to 'Modal'.


You can create toolbars with toggle tools using GUIDE.

Introduced before R2006a