开发者

Can Items in a JList be formatted as HTML

I would like to create a JList in Java so that each individual item is formattted开发者_开发问答 using HTML tags, but I'm not clear how to do this or even if this is possible. Does anyone have any suggestions?

Thank you.


Its actually very simple. For every string in the list surround it with the html tags such as this:

<html><font color=green>this will be green</font></html>

When the JList displays it it will be green.


Swing supports the use of HTML in many of the controls that display text.

In your case the JList is actually using a JLabel to display each item, so you just need the list model to return the string values in the list as HTML and it should all work.

Alternately you can write a javax.swing.ListCellRenderer that converts the value in the list to HTML.

There's some more info on Swing's HTML support here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜