MATLAB: Changing color of a string in listbox – MATLAB GUI

guilistboxuitable color

I have a list of names in a listbox. What I would like to do is have a certain selected name change color, from red to green, when I click a button.
Thank you

Best Answer

Don't add the name directly: add the HTML-ized version of the name.
htmlname = sprintf('<HTML><BODY bgcolor="%s">%s', 'red', ThisEntryName);
And in the callback:
namestr = cellstr(get(hObject, 'String'));
validx = get(hObject, 'Value');
newstr = regexprep(namestr{validx}, '"red"','"green"');
namestr{validx} = newstr;
set(hObject, 'String', namestr);