How to change color of each individual string in a app.listbox?

6 views (last 30 days)
I can use the following code,which is useful in GUI:
a = {'<HTML><FONT color="red">Red</FONT></HTML>', ...
'<HTML><FONT color="green">Green</FONT></HTML>', ...
'<HTML><FONT color="blue">Blue</FONT></HTML>'};
figure; uicontrol('Style','list','Position',[100 100 100 100],'String', ...
a);
But it is not work in Appdesigner:
app.ListBox.Items = {'<HTML><FONT color="red">Red</FONT></HTML>'};
So is it possible in Appdesigner?

Answers (1)

Akanksha
Akanksha on 10 Jun 2025
Hey kevin eyre,
App Designer uses web-based UI components (based on JavaScript and HTML rendering in a different way), and these components do not support HTML tags in the Items property. So, colored or styled text using HTML is not rendered.
Following is the app designer Compatible Code Using UITable with Colors that can help with the query :
functionstartupFcn(app)
% Sample data
data={'Red';'Green';'Blue'};
% Set data to UITable
app.UITable.Data=table(data,'VariableNames',{'Color'});
% Apply colors using uistyle
redStyle=uistyle('BackgroundColor',[10.80.8]);
greenStyle=uistyle('BackgroundColor',[0.810.8]);
blueStyle=uistyle('BackgroundColor',[0.80.81]);
% Apply styles to each row
addStyle(app.UITable,redStyle,'row',1);
addStyle(app.UITable,greenStyle,'row',2);
addStyle(app.UITable,blueStyle,'row',3);
end
Here’s the screenshot attached using the above code -
PFA the links for further reference
Hope this helps!
  1 Comment
JKMSMKJ
JKMSMKJ on 10 Jun 2025
Hi Kevin & Akanksha,
uistyle can be used directly for uilistbox (since R2023a), so mirroring what worked for figure/GUIDE (which no longer does since R2025a), we can do the following:
a={'<p style="color:red;">Red</p>',...
'<p style="color:green;">Green</p>',...
'<p style="color:blue;">Blue</p>'};
app.listbox=uilistbox(uifigure,Position=[100 100 100 100],Items=a); %Parent is uifigure!
addStyle(app.listbox,uistyle("Interpreter","html"));
Hope this works for your use case as expected!

Sign in to comment.

Categories

Find more on Desktop in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!