tags:

views:

35

answers:

2

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.

+1  A: 

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.

Nick Holt
This should work, just remember that embedding images in HTML code won't work when using Swing.
Abel Morelos
@Abel - good point, should've said it's only really a subset of HTML that's supported.
Nick Holt
+1  A: 

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.

Mike
This was all I needed. Thanks.
Elliott