Listbox words not aligning up after using HTML for changing string color

Hi,
I'm having some issues with the text alignment in one of my Listboxes due to using HTML to change the color properties of each individual string. I was wondering if there's anything that I could do to fix the problem and have the letters alligne just like the first Listbox(left)?
I've tried to change the Listbox font but with no effect. I am positive that the reason why the lettes dont align is because of the HTML line/code implemented to charge the string property, since once I remove the code or not use it(as shown in figure 1, left) the letters allign properly.
Thank you
code used to for string color manipulation:
line = sprintf('<HTML><BODY bgcolor="transparent" text="blue" >%s',line);

 採用された回答

Jan
Jan 2013 年 1 月 3 日
編集済み: Jan 2013 年 1 月 7 日
str = sprintf('<HTML><FONT color="blue" face="monospace">%s', str);
You can get the font name of the listbox explicitly:
FontName = get(ListBoxHandle, 'FontName');
str = sprintf('<HTML><FONT color="blue" face="%s">%s', FontName, str);
Btw, using the symbol "line" as name of a variable shadows the built-in function with the same name.
[EDITED] In HTML several neighboring spaces are displayed as one space. Therefore try this to convert the string:
str = strrep(str, ' ', '&ampnbsp;');
str = sprintf('<HTML><FONT color="blue" face="monospace">%s', str);
PS. Creating the string "&ampnbsp;" is not trivial in the forum, because this is displayed as non-braking space. Therefore I had to escape the & by using the HTML special character.

5 件のコメント

Vincent I
Vincent I 2013 年 1 月 7 日
編集済み: Vincent I 2013 年 1 月 7 日
Jan, I've tried your first method before posting my issue and it did not work.
I've tried your second method and it did not work either. I know it might sound strange but I think it has something to do with the HTML color changing text rather than the displayed text. As long as I dont HTML edit the code everything is fine.
Any other sugestions? Thank you
Jan
Jan 2013 年 1 月 7 日
編集済み: Jan 2013 年 1 月 7 日
See [EDITED]
Vincent I
Vincent I 2013 年 1 月 7 日
Fantastic Jan it worked. thank you very much
Jan
Jan 2013 年 1 月 7 日
@Vicent: Fine! Again we have won the battle between human and human made computers.
Vincent I
Vincent I 2013 年 1 月 7 日
haha :-)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDesktop についてさらに検索

質問済み:

2013 年 1 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by