removeStyle - Remove style from UI component - MATLAB (original) (raw)
Remove style from UI component
Syntax
Description
removeStyle([comp](#mw%5F4af699b3-60a3-45b5-96d8-d10a92c49257))
removes all styles created with the uistyle function from the specified table, tree, list box, or drop-down UI component. To determine which styles are on comp
and available to remove, query the value ofcomp.StyleConfigurations
.
removeStyle([comp](#mw%5F4af699b3-60a3-45b5-96d8-d10a92c49257),[ordernum](#mw%5F43b79cfc-8cfe-46be-9d8e-8dd213407b19))
specifies which style to remove. Specify a style based on the order in which it was added. The property comp.StyleConfigurations
lists styles in the order that they were added.
Examples
First, add two styles to a tree.
fig = uifigure; fig.Position = [100 100 250 350]; t = uitree(fig); n1 = uitreenode(t,'Text','Fruits'); n11 = uitreenode(n1,'Text','Banana'); n12 = uitreenode(n1,'Text','Cherry'); n2 = uitreenode(t,'Text','Vegetables'); n21 = uitreenode(n2,'Text','Broccoli'); n22 = uitreenode(n2,'Text','Lettuce'); expand(t)
s1 = uistyle('FontColor',[0 0.4 0.7]); s2 = uistyle('FontColor',[0.1 0.5 0.1]);
addStyle(t,s1,'level',2); addStyle(t,s2,'node',[n2 n21 n22]);
Then, remove both styles to revert the tree to its default appearance.
Add multiple styles to a table UI component, and then remove some of them.
First, create a table UI component and add styles to different parts of it.
fig = uifigure; fig.Position = [500 500 720 230]; uit = uitable(fig); uit.Data = randi([-20,20],7); uit.Position = [20 30 680 185];
[row,col] = find(uit.Data<0);
s1 = uistyle; s1.BackgroundColor = 'cyan'; addStyle(uit,s1,'column',[1 3 5])
s2 = uistyle; s2.FontColor = 'red'; s2.FontWeight = 'bold'; addStyle(uit,s2,'cell',[row,col])
s3 = uistyle('BackgroundColor','green'); addStyle(uit,s3,'row',[3 4])
addStyle(uit,s1,'column',7)
Now, remove the row and column styles. First, query the value of theStyleConfigurations
property for the table.
ans=4×3 table
Target TargetIndex Style
______ _____________ ___________________________
1 column { 1x3 double} [1x1 matlab.ui.style.Style]
2 cell {20x2 double} [1x1 matlab.ui.style.Style]
3 row { 1x2 double} [1x1 matlab.ui.style.Style]
4 column {[ 7]} [1x1 matlab.ui.style.Style]
The StyleConfigurations
property value shows that style order numbers 1
and 4
affect columns, and that the row style was the third style added to the table. Remove the styles by specifying style order numbers 1
, 3
, and4
.
Input Arguments
UI component, specified as one of these UI components:
- A
Table
object created with theuitable
function - A
Tree
object created with theuitree
function - A
ListBox
object created with theuilistbox
function - A
DropDown
object created with theuidropdown
function
The component object must be parented to a figure created with theuifigure
function or to one of its child containers.
Style order number, specified as a positive integer or a vector of positive integers. To determine the styles currently applied to the table, and the order in which they were added, query the value of the StyleConfigurations
property.
When you remove a style other than the last one that was added, the remaining styles move up in the order to close the gaps. If no style order number is specified, all styles are removed from the UI component.
Example: removeStyle(comp,2)
removes the second style in the list returned by comp.StyleConfigurations
.
Example: removeStyle(comp,[1 3 5])
removes the first, third, and fifth styles in the list returned bycomp.StyleConfigurations
.
Example: removeStyle(comp)
removes all styles from the UI component.
Version History
Introduced in R2019b
To remove a style from a list box or drop-down UI component, specify theListBox
or DropDown
object as the first argument to the removeStyle
function.
To remove a style from a tree, specify the Tree
object as the first argument to the removeStyle
function.