0

I tried using a custom TableCellRenderer that extends JLabel - This displays just what I want. By default JLabel 'recognizes' HTML

`<html><body><img src='http://www......jpg'><br>Some Text
<a href='http://www.myDomain.com'>Click Here</a>Some More Text</body></html>`

But JLabel does not implement addHyperlinkListener, so a click on the link is never honored.

If I then try the same with TableCellRenderer that extends JTextPane, then the 'image' is not displayed, just the default 'broken' image. In this case JTextPane does implement addHyperlinkListener, but again it is not honored. (Yes, I created a listener.)

If I then try the same with TableCellRenderer that extends JEditorPane, then again the 'image' is not displayed, just the default 'broken' image. In this case JTextPane does implement addHyperlinkListener, but again it is not honored. (Yes, I created a listener.)

eboix
  • 5,113
  • 1
  • 27
  • 38

1 Answers1

4

No matter how many listeners you register to the components returned by the TableCellRenderer, they will never be called. The component is not contained in the table but only used as a stamp. As a result, events will never reach those listeners. This concept is explained in the Swing table tutorial (in the Renderers and Editors section).

You can take a look at the Table Button column example which adds a clickable button in a JTable. The same concept can be used to include a hyperlink in a JTable.

You might also find the following SO question about "Adding a hyperlink in a JLabel" interesting.

Community
  • 1
  • 1
Robin
  • 36,233
  • 5
  • 47
  • 99