uifigure内で描画したuitableのColumnNameに背景色をつけるには
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
App Designerでuitableを表示する際、ColumnNameの欄に背景色をつけたいです。
調べたところ、html書式使えばColumnNameをある程度編集できるそうですが、App Designer上ではhtmlが反映されません。
% uitableの要素を設定
headers = {'Name 1', ...
'<html><center><font color = "red">Name<br />2</font></center></html>', ...
'<html><center><p style="background-color:#00FF00">Name<br />3</p></center></html>', ...
'<html><center>Name<br />4</center></html>'};
data = {1,2,3,4};
% figureでの描画
fig1 = figure;
table1 = uitable(fig1, 'Data',data, 'ColumnName',headers);
% uifigureでの描画
fig2 = uifigure;
table2 = uitable(fig2, 'Data',data, 'ColumnName',headers);
解決法をご存じでしたら教えてください。
また他の方法でColumnNameに背景色をつける方法があれば教えていただきたいです。
1 commentaire
Réponses (1)
Avni Agrawal
le 18 Déc 2023
Modifié(e) : Avni Agrawal
le 18 Déc 2023
Hi Fujita,
I understand that you want to add background color and custom styling to ‘ColumnName’. HTML is not yet recognized in AppDesigner. But there is a workaround using ‘uilabel’ to format column/row headers in ‘uitable’.
The ‘uilabel’ components with ‘BackgroundColor’ properties are used to create colored headers. You would need to synchronize the widths and positions of the labels with the columns of the table manually.
Here is an example of how you can use ‘uilabel’ to change the background color of table headers:
function startupFcn(app)
% New data to be added to the table
newData = {
'John Doe', 28, true;
'Jane Smith', 34, false;
'Mike Brown', 45, true
};
% Set the new data to the table
app.UITable.Data = newData;
% Calculate positions for the labels
tablePosition = app.UITable.Position;
headerHeight = 25; % Example header height
labelY = tablePosition(2) + tablePosition(4) - headerHeight;
% Assuming you have 3 columns
columnNames = {'Column 1', 'Column 2', 'Column 3'};
columnWidths = {100, 100, 100}; % Example column widths
app.HeaderLabels = gobjects(1, length(columnNames));
% Create header labels as properties in the app
for i = 1:length(columnNames)
labelX = tablePosition(1) + sum([columnWidths{1:i-1}]);
app.HeaderLabels(i) = uilabel(app.UIFigure, ...
'Text', columnNames{i}, ...
'Position', [labelX, labelY, columnWidths{i}, headerHeight], ...
'BackgroundColor', [1 0 0], ... % Example gray color
'HorizontalAlignment', 'center');
end
end
Please refer to the following documentation page for more information on the ‘uilabel’ function:
I hope this helps.
0 commentaires
Voir également
Catégories
En savoir plus sur App Designer を使用したアプリ開発 dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!