Main Content

removeStyle

Remove style from table or tree UI component

Description

example

removeStyle(comp) removes all styles created with the uistyle function from the specified table or tree UI component. To determine which styles are on comp and available to remove, query the value of comp.StyleConfigurations.

example

removeStyle(comp,ordernum) 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

collapse all

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]);

A tree with nodes listing fruits and vegetables. The Banana and Cherry nodes are blue, and the Vegetables, Broccoli, and Lettuce nodes are green.

Then, remove both styles to revert the tree to its default appearance.

removeStyle(t)

A tree with nodes listing fruits and vegetables. All node font is black.

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)

Table UI component with 7 columns and 7 rows. The negative-valued data is displayed in bold red text. Cells in rows 3 and 4 and between columns 1 and 6 are green. The remaining cells in columns 1, 3, and 5 are cyan. All of the cells in column 7 are cyan.

Now, remove the row and column styles. First, query the value of the StyleConfigurations property for the table.

uit.StyleConfigurations
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, and 4.

removeStyle(uit,[1 3 4])

Table UI component. The negative-valued data is displayed in bold red text. All cells have the default background color.

Input Arguments

collapse all

UI component, specified as a Table object created with the uitable function or a Tree object created with the uitree function. The component object must be parented to a figure created with the uifigure function, or 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 by comp.StyleConfigurations.

Example: removeStyle(comp) removes all styles from the UI component.

Introduced in R2019b