• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help me with custom TreeCellRenderer (JTree)

 
Haiti Meid
Greenhorn
Posts: 13
Chrome Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For an overview: I'm writing an email reader (via IMAP + SSL). I'm using JTree and custom EmailMessageCellRenderer to display e-mail info (sender/ date/ subject) in a PanelEmailMessage.

Here is my EmailMessageCellRenderer:



The problem is at line (*): I use only one PanelEmailMessage for one instance of EmailMessageCellRenderer. And in most of time, that panel displays a bad looking as below picture:


But if for any call to method getTreeCellRendererComponent() I create new PanelEmailMessage and return to the caller, everything will be ok.

So my question is: which use is correct way in my case? Currently I'm using private final PanelEmailMessage (as above code) to save memory. Because I think for 20 e-mails, if I use way #2, I will make 20 PanelEmailMessage(s).

Thanks in advance.
 
Haiti Meid
Greenhorn
Posts: 13
Chrome Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm sorry that was my bug in PanelEmailMessage. But now may I ask you which use is correct? Do I need only one PanelEmailMessage, or need to create new one for every call to getTreeCellRendererComponent()?
 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll find the answer to that in the first two paragraphs of the tutorial section Concepts: Editors and Renderers.
 
Haiti Meid
Greenhorn
Posts: 13
Chrome Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is wonderful! Thank you so much. I have been googling for hours to find that webpage. My hobby is googling forums first - not reading the documentation. Now I know that is bad hobby.

You save my time a lot, thank you again :-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!