uitable のセルにおいて、データ表示の横位置を変更することはできますか?
14 views (last 30 days)
Show older comments
MathWorks Support Team
on 15 Jan 2020
Edited: MathWorks Support Team
on 15 Jan 2020
uitable オブジェクト(テーブル)のセルに表示された数値、文字を任意に"左寄せ"、"中央"、"右寄せ"に変更する方法を教えてください。
Accepted Answer
MathWorks Support Team
on 15 Jan 2020
Edited: MathWorks Support Team
on 15 Jan 2020
■R2019b 以降のリリースの場合
uifigure もしくは、AppDesigner 上に表示されるテーブルであれば、uistyle および addStyle 関数を使って、横方向の位置を変更することが可能です。
fig = uifigure;
uit = uitable(fig);
uit.Data = rand(5,3);
s = uistyle('HorizontalAlignment','center'); % 中央寄せのスタイルを作成
addStyle(uit,s) % スタイルをテーブルに適用
figure, GUIDE 上に表示したテーブルを対象としている場合は、以下の内容を参考にしてください。
■R2019a 以前のバージョンの場合
残念ながら、データ表示の位置を変更する機能は提供されていません。
代替案として、数値から文字列に変換して右寄せに変更したり、スペースを利用して表示位置を調節する方法をご検討ください。
fig = figure;
uit = uitable(fig);
uit.Data = rand(5,3);
data = num2cell(uit.Data); % テーブルデータ(行列)をセル配列に変換
data2 = cellfun(@num2str,data,'UniformOutput',false); % 文字列に変換
uit.Data = data2; % テーブルに適用し、左寄せ
% 12文字になるようにスペースを挿入して調整
data2 = cellfun(@(s)sprintf('%*s',12,s),data2,'UniformOutput',false);
uit.Data = data2; % テーブルに適用し、中央寄せ風
0 Comments
More Answers (0)
See Also
Categories
Find more on uifigure ベースのアプリ in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!