Change Color of each individual String in a Listbox ?
이전 댓글 표시
Hey Guys,
I want to give each Word in my List box an specific color. My mentor said: its not possible. Now I ask here: is it possible to chose the Color of Listbox text with the RGB system ?
채택된 답변
추가 답변 (4개)
Adam
2014년 9월 1일
Slightly modified example of code Yair Altman posted many years ago:
figure; uicontrol('Style','list', 'String', ...
{'<HTML><FONT color="red">Red</FONT></HTML>', ...
'<HTML><FONT color="green">Green</FONT></HTML>', ...
'<HTML><FONT color="blue">Blue</FONT></HTML>'} );
댓글 수: 7
Max Müller
2014년 9월 1일
Adam
2014년 9월 1일
It's just using the fact that underlying Matlab UI controls are Java controls and you can do things like use HTML markup in those.
You can also do things like create a multi-line Pushbutton string which I have often found useful, using HTML.
Image Analyst
2014년 9월 1일
Yair Altman
2014년 9월 4일
편집: Yair Altman
2014년 9월 4일
Here's an article explaining all this: http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents
And related code/images (note that it's case-insensitive and that you don't have to close the HTML tags):
uicontrol('Style','list', 'Position',[10,10,70,70], 'String', ...
{'<HTML><FONT color="red">Hello</Font></html>', 'world', ...
'<html><font style="font-family:impact;color:green"><i>What a', ...
'<Html><FONT color="blue" face="Comic Sans MS">nice day!</font>'});

Keqin Xu
2019년 10월 31일
Trouble is, when there are "<" in the string, the "<" are all missing in the listbox!
Any ideas to fix it? Thanks!
Adam
2019년 11월 1일
You can use <, > for < and >
Max Müller
2014년 9월 1일
0 개 추천
댓글 수: 4
Adam
2014년 9월 1일
I'm not really familiar with HTML myself, I just learn on a "need to know" basis. I know you can use hex colour codes (I did it myself for the first time last week) rather than named colours, but I'm not sure about RGB colours...
Guillaume
2014년 9월 1일
Well, hex colour code is just red, green, blue (in that order) encoded as 2 bytes hexadecimal on a scale of 0 to 255.
e.g: red = 0, green = 126 (7E), blue = 255 (FF) => hex = 007EFF
Adam
2014년 9월 1일
dec2hex( [r g b] )
should help convert between the two, although you have to scoop up the 3 rows of the result into a single string to put into the html string.
Guillaume
2014년 9월 2일
That would be:
reshape(dec2hex([r g b], 2)',1, 6)
Max Müller
2014년 9월 2일
0 개 추천
댓글 수: 1
Image Analyst
2014년 9월 2일
Max, this is not an official "Answer" to your original question. If anything, it should have been a Comment to some other response.
Max Müller
2014년 9월 2일
0 개 추천
댓글 수: 2
Adam
2014년 9월 2일
Please don't keep adding new questions as answers, it is confusing.
You can define the colour of independent static text objects easily enough (or indeed any independent objects like that if they are predefined).
If you want to have different coloured backgrounds or text in a listbox or uitable or similar though then I'm not aware of any alternative to using html and/or the underlying java UI programming as discussed in previous answers.
If you can explain which element of the suggested solution you are having a problem with we can assist further on that.
Max Müller
2014년 9월 2일
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!