for UITABLE: BackgroundColor for row
5 ビュー (過去 30 日間)
古いコメントを表示
hello,
i have problem in GUI, for UITABLE the BackgroundColor are for every row but i want BackgroundColor for every colomn please help me,
.
for exemple:
f = figure('Position', [100 100 752 350]); t = uitable('Parent', f, 'Position', [25 25 700 200]);
set(t, 'Data', magic(10));
foregroundColor = [1 1 1]; set(t, 'ForegroundColor', foregroundColor); backgroundColor = [.4 .1 .1; .1 .1 .4]; set(t, 'BackgroundColor', backgroundColor);
.
thank you in advance
faithfully;
0 件のコメント
採用された回答
Walter Roberson
2013 年 4 月 12 日
You cannot directly set colors per column (unless it can be done at the Java level.)
The work-around is to change the column to string format, convert the numeric values to string, and wrap each string with an HTML code to change the color.
bgcols = floor(255 * [.4 .1 .1;.1 .1 .4]);
colfmtstr = sprintf('<HTML><TABLE><TD bgcolor="rgb(%d,%d,%d)"%%g', bgcols(1,:));
colcontents = cellstr( num2str(magic(10), colfmtstr) );
then make colcontents one of the columns of the data. Change the color for a different column by changing the (1,:) to (2,:)
2 件のコメント
Walter Roberson
2013 年 4 月 12 日
編集済み: Walter Roberson
2015 年 12 月 19 日
Sorry, I forgot that num2str() needs data in columns to work the way I was thinking of. Also, I did some work on getting the columns to look better.
f = figure('Position', [100 100 752 350]);
t = uitable('Parent', f, 'Position', [25 25 700 200], 'FontName', 'courier'); %fixed-width font but not 'fixed' itself
desiredcellwid = 10; %adjust as needed
fgcols = floor(255 * [1 1 1]);
bgcols = floor(255 * [.4 .1 .1;.1 .1 .4]);
colprestr = sprintf('<HTML><TABLE><TD color="rgb(%d,%d,%d)" bgcolor="rgb(%d,%d,%d)">', fgcols(1,:), bgcols(1,:));
numfmt = '%g';
msquare = magic(10);
for K = 1 : size(msquare,2)
Tcol = cellstr(num2str(msquare(:,K), numfmt));
Tcol = cellfun(@(s) [blanks(desiredcellwid - length(s)), s], Tcol, 'Uniform', 0);
Tcol = strcat( colprestr, regexprep(Tcol, ' ', ' ') );
colcontents(:,K) = Tcol;
end
set(t, 'Data', colcontents);
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!