Main Content

removeStyle

UI コンポーネントからスタイルを削除

R2019b 以降

説明

removeStyle(comp) は、指定されたテーブル、ツリー、リスト ボックス、またはドロップダウンの UI コンポーネントから関数 uistyle で作成されたすべてのスタイルを削除します。comp にある削除対象となるスタイルを確認するには、comp.StyleConfigurations の値をクエリします。

removeStyle(comp,ordernum) は、削除するスタイルを指定します。スタイルは追加された順序に基づいて指定します。comp.StyleConfigurations プロパティには、追加された順序でスタイルがリストされます。

すべて折りたたむ

まず、2 つのスタイルをツリーに追加します。

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.

次に、両方のスタイルを削除して、ツリーを既定の外観に戻します。

removeStyle(t)

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

テーブル UI コンポーネントに複数のスタイルを追加し、そのうちの一部を削除します。

まず、テーブル UI コンポーネントを作成し、そのさまざまな部分にスタイルを追加します。

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.

次に、行と列のスタイルを削除します。最初に、テーブルの StyleConfigurations プロパティの値をクエリします。

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]

StyleConfigurations プロパティの値から、スタイル順序番号 14 が列に影響し、行スタイルはテーブルに追加された 3 番目のスタイルであることがわかります。スタイル順序番号 134 を指定してスタイルを削除します。

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.

入力引数

すべて折りたたむ

UI コンポーネント。次の UI コンポーネントのいずれかとして指定します。

  • 関数 uitable で作成された Table オブジェクト

  • 関数 uitree で作成された Tree オブジェクト

  • 関数 uilistbox で作成された ListBox オブジェクト

  • 関数 uidropdown で作成された DropDown オブジェクト

コンポーネント オブジェクトは、関数 uifigure で作成された Figure またはその子コンテナーのうちの 1 つを親としなければなりません。

スタイル順序番号。正の整数、または正の整数のベクトルとして指定します。テーブルに現在適用されているスタイルとそれらが追加された順序を確認するには、StyleConfigurations プロパティの値をクエリします。

最後に追加されたスタイル以外のスタイルを削除すると、隙間を埋めるために残りのスタイルの順序が上がります。スタイル順序番号を指定しない場合、すべてのスタイルが UI コンポーネントから削除されます。

例: removeStyle(comp,2) は、comp.StyleConfigurations から返されるリストの 2 番目のスタイルを削除します。

例: removeStyle(comp,[1 3 5]) は、comp.StyleConfigurations から返されるリストの 1 番目、3 番目、5 番目のスタイルを削除します。

例: removeStyle(comp) は、すべてのスタイルを UI コンポーネントから削除します。

バージョン履歴

R2019b で導入

すべて展開する