Changing color of a string in listbox - MATLAB GUI
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Walter Roberson
le 14 Juin 2012
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);
1 commentaire
Plus de réponses (6)
Tom
le 14 Juin 2012
You can do it with html- see http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/
0 commentaires
Vincent I
le 14 Juin 2012
1 commentaire
Dr. Seis
le 14 Juin 2012
What you are generally describing above should work with HTML... can you post a few pictures of what you envision? Or can you post the cell-string you are using to apply to the listbox... there might be a formatting issue that is preventing it from working.
Vincent I
le 18 Juin 2012
1 commentaire
Walter Roberson
le 18 Juin 2012
namestr(validx) = []; %delete it from where it was
namestr = [ {newstr}; namestr ];
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox 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!