Simulate web links in Swing using labels? Best/most dynamic way?

What's the best way to simulate something like a clickable web link in Swing? I want to list (for example) people's names vertically on a page so that when you move the mouse over each name the font changes to underline. Also when you click a name a new window opens (that part I can do).

Using Netbeans I created say ten labels, called NameOne .. NameTen. In the code when I've read the names from the database I manually set each label's text to the appropriate name.

I added code to change the colour of the label (for now) when the mouse enters and exits the widget.

This all seems rather hard coded (in terms of variable names) and convoluted. Any suggestions for better ways to do this?

Thanks

[734 byte] By [BobCrivensa] at [2007-11-27 6:47:03]
# 1
Use a JEditorPane. It supports hyperlinks.
camickra at 2007-7-12 18:19:35 > top of Java-index,Desktop,Core GUI APIs...
# 2

True, but how would I respond to clicking a piece of text? Apart from the obvious of detecting a mouse click inside the editor pane. I don't want to open a web page when I click; I want to open a new window. I guess I don't see how to connect it all together. But thanks, I'll research the editor pane.

Thanks!

BobCrivensa at 2007-7-12 18:19:35 > top of Java-index,Desktop,Core GUI APIs...
# 3
Ah, ok: http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.htmlSounds like it's just what I need.Thanks!
BobCrivensa at 2007-7-12 18:19:35 > top of Java-index,Desktop,Core GUI APIs...
# 4
If you read the JEditorPane API it shows you how to use a HyperlinkListener. Not sure why you had to search the web or that information. Always start with the API.
camickra at 2007-7-12 18:19:35 > top of Java-index,Desktop,Core GUI APIs...
# 5
Thanks - I managed to get it working. I keep forgetting that the javadocs includes examples and they're not just the API.
BobCrivensa at 2007-7-12 18:19:35 > top of Java-index,Desktop,Core GUI APIs...