Can Items in a JList be formatted as HTML

我怕爱的太早我们不能终老 提交于 2019-11-29 14:02:00

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!