Multi-colored pop-up menu entries

Is there a way to make a gui pop-up menu display its list of selections with different text colors? What about different fonts and typesetting (Italics, Boldface, etc...)

 Accepted Answer

Yes, try this:
uicontrol('style','popup','string',{'<FONT COLOR="red" SIZE="10" FACE="ARIAL">*_Here_*','<FONT COLOR="blue" SIZE="4" FACE="Courier">*There*','<FONT COLOR="maroon" SIZE="6" FACE="GEORGIA">Anywhere'})
Basically, I'm just using HTML. Take a look at each element in the cell of strings. Here is the first one.
'<FONT COLOR="red" SIZE="10" FACE="ARIAL">*_Here_*'
There are many ways you can format text in HTML. You can find that in google, but if you have no idea at all, you can start by taking a look at http://www.tizag.com/htmlT/font.php and then try to find other more complete tutorials if you need so.
Hope this helps. Best regards

2 Comments

Thanks!
Matt J
Matt J about 1 hour ago
Edited: Matt J about 1 hour ago
Retesting this in R2026a. It still seems to work, on Windows at least.
f = figure( ...
'Position',[500 500 350 180], ...
'Name','Formatted Popup Example', ...
'MenuBar','none');
items = { ...
'<html><font color="red">Red text</font></html>', ...
'<html><font color="blue"><b>Blue bold text</b></font></html>', ...
'<html><font color="green"><i>Green italic text</i></font></html>', ...
'<html><font face="Courier New" color="purple"><b><i>Courier bold italic</i></b></font></html>', ...
'<html>Plain <b>bold</b> and <i>italic</i> mixed</html>'};
uicontrol(f, ...
'Style','popupmenu', ...
'String',items, ...
'Position',[50 100 250 30], ...
'FontSize',12);

Sign in to comment.

More Answers (1)

Matt Stead
Matt Stead on 22 Dec 2024
Edited: Matt Stead on 22 Dec 2024
This worked better for me. Largely copied & pasted from something I'm working on, so edit as necessary.
% set colors
DARK_RED = [0.63 0.08 0.18];
DARK_ORANGE = [0.91 0.45 0.05];
DARK_YELLOW = [0.93 0.69 0.13];
DARK_GREEN = [0.0 0.45 0.0];
DARK_BLUE = [0.0 0.45 0.74];
DARK_PURPLE = [0.49 0.18 0.56];
% build HTML strings
part1 = '<HTML><FONT bgcolor="';
part2 = '" color="';
part3 = '">&nbsp &nbsp &nbsp<FONT bgcolor="#FFFFFF" color="#000000">&nbsp ';
part4 = '</FONT></HTML>';
hex_str = sprintf('#%02x%02x%02x', round(DARK_RED(1) * 255), round(DARK_RED(2) * 255), round(DARK_RED(3) * 255));
hmtl_strings{1} = [part1 hex_str part2 hex_str part3 'Red' part4];
hex_str = sprintf('#%02x%02x%02x', round(DARK_ORANGE(1) * 255), round(DARK_ORANGE(2) * 255), round(DARK_ORANGE(3) * 255));
hmtl_strings{2} = [part1 hex_str part2 hex_str part3 'Orange' part4];
hex_str = sprintf('#%02x%02x%02x', round(DARK_YELLOW(1) * 255), round(DARK_YELLOW(2) * 255), round(DARK_YELLOW(3) * 255));
hmtl_strings{3} = [part1 hex_str part2 hex_str part3 'Yellow' part4];
hex_str = sprintf('#%02x%02x%02x', round(DARK_GREEN(1) * 255), round(DARK_GREEN(2) * 255), round(DARK_GREEN(3) * 255));
hmtl_strings{4} = [part1 hex_str part2 hex_str part3 'Green' part4];
hex_str = sprintf('#%02x%02x%02x', round(DARK_BLUE(1) * 255), round(DARK_BLUE(2) * 255), round(DARK_BLUE(3) * 255));
hmtl_strings{5} = [part1 hex_str part2 hex_str part3 'Blue' part4];
hex_str = sprintf('#%02x%02x%02x', round(DARK_PURPLE(1) * 255), round(DARK_PURPLE(2) * 255), round(DARK_PURPLE(3) * 255));
hmtl_strings{6} = [part1 hex_str part2 hex_str part3 'Purple' part4];
% build popup
recPopup = uicontrol('Parent', d, ...
'Position', [10 (y_offset + 5) 110 17], ...
'Style', 'popupmenu', ...
'FontSize', SYS_FONT_SIZE, ...
'String', hmtl_strings, ...
'Value', 1, ...,
'HorizontalAlignment', 'left', ...
'Interruptible', 'off', ...
'BusyAction', 'cancel');

2 Comments

2025a seems to have broken this method (at least on Linux). Does anyone know what to do now?
Matt J
Matt J on 13 Jun 2025
Edited: Matt J on 13 Jun 2025
What about the original answer that was proposed, and accepted?

Sign in to comment.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Asked:

on 11 Jun 2013

Edited:

on 18 Sep 2026 at 2:26

Community Treasure Hunt

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

Start Hunting!