• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextPane as CellRenderer in JTable

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

I'm trying to put a JTextPane as cellrenderer. It works if I make a new instance of a JTextPane but if I extend JTextPane the text is invisible.

Example when not extending, Working but very slow?



It does not work when extending.
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mathias Nilsson:
Hi!

I'm trying to put a JTextPane as cellrenderer. It works if I make a new instance of a JTextPane but if I extend JTextPane the text is invisible.



I don't know exactly what these CustomHTMLEditorKit, MutableHTMLDocument, and CellBorder classes are doing but in the implements TableCellRenderer one, providing this firePropertyChange() method is pointless. It becomes a new method (which is never called) in the CellTableRenderer class and doesn't override anything in the Component returned by the getTableCellRendererComponent() method. (Same goes for the other three methods.)

In the extends JTextPane one, this does override the method from the superclass. That's probably your problem. Listeners aren't being notified when you set a new Document onto the renderer. If you remove that code (so that the superclass method is simply inherited) then it should work. Alternatively you could override it like this

so the document change events get through even if the others don't.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot!

It worked. My fault. I read this in a swing book to override the method for speed. Haven't really
know what the methods do. It works now a little faster but still a little to slow for 500 cells.

A user will type in HTML in every cell with bold, italic, paragraphs, colors and so on. Is there another way of doing this faster. Any pointers?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!