Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable CellRenderer with HTML in JLabel  RSS feed

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I have a Renderer for a Jtable that extends JLabel and implements TableCellRenderer( I have altso trie d with DefaultTableCellRenderer ).

I want my JLabel to display HTML but it's not working. I call setTest( html ) int getTableCellRendererComponent but it displays my html as a string with all the tags visible. Anyone have a clue? Isn't it possible to display HTML in a JLabel component?
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This uses DefaultTableCellRenderer (also a JLabel subclass) and works perfectly; the second row shows an italic, underlined, bold "HTML" value.

Can you show us the code for your custom renderer and the value you're setting? My guess is that either is causing the problem.

Keep in mind though that when you edit the field you will get the complete HTML string, unless you use a custom table cell editor as well.
[ November 02, 2007: Message edited by: Rob Prime ]
 
Brian Cole
Author
Ranch Hand
Posts: 947
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mathias Nilsson:
Isn't it possible to display HTML in a JLabel component?


Yes, but the text is interpreted as HTML only if the first six characters are <html> (case doesn't matter). Also, not all HTML constructs work, mostly just the simple stuff.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still doesn't work in a CellRenderer. Can you post your code to get this to work? I can't make an new instance of JLabel only setText() return this.

To slow otherwise.
 
Brian Cole
Author
Ranch Hand
Posts: 947
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mathias Nilsson:
Still doesn't work in a CellRenderer. Can you post your code to get this to work?


Wouldn't it make more sense for you to post your code so we can examine it and try to explain where you're going wrong? I still have no idea what you are trying to do beyond the general jlabel/html/renderer context.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!