Hi Sachin,

Thanks for you reply. You seemed doing more complex work with JTree than me. For my work I only need to set different DefaultTreeCellRenderer's (of course JLabel) height at the moment, but your advice is definitely useful for my future work.

Coincidentally I just got the problem sorted last night. I would like to tell you and the others in this forum to share my experience. This problem seemed to be straight forward as my first thought. However there is a little trick behind the scene. At first, I used myJTree.setRowHeight(0) to invalid any default row height (myJTree is a instance of JTree) and wrote:

if (row == 1)

setPreferredSize(new Dimension(100, 50)); // all are test values

It unexpectedly applied to all nodes instead of only for the node in the second row. I stuck for so long. However a extra else would solve it. The code should be like below:

if (row == 1)

setPreferredSize(new Dimension(100, 50)); // all are test values

else

setPreferredSize(new Dimension(100, 20)); // default values for other nodes

The first experience is that once you set a preferred height of a node (with 0 height for a JTree's row height) for the first time. This height is also chosen as default height for all the other nodes. You must set a default height explicitly. The second is that even though you use myJTree.setRowHeight(0), there is still a non-zero default value for all nodes if you did not set a preferredHeight of the cellRenderer.

Hope that is useful for all and thanks again Sachin !

Best regards,

George Song

 

 Sachin Hejip <[EMAIL PROTECTED]>wrote:

Hi,
 
The way I do it is to set the preferredsize of the TreeCellRenderer for each cell it is rendering.
e.g. in my application I have to show a node with text and arbitrary amount of detail below it.
So, I have a JPanel with a JLabel and a JTextArea in a BorderLayout as my TreeCellRenderer.
For each getTreeCellRendererComponent, I set the data and call doLayout and return the JPanel.
The JTree takes care of the rest.
 
Hope this helps.
 
Best Regards
Sachin
----- Original Message -----
From: a johnston
Sent: Thursday, September 19, 2002 3:20 AM
Subject: Set different node's height in JTree

Hi All,

Does anyone know how to set a node's height in JTree according to their row number? This is a feature I am trying to use for highlighting purposes.  I have searched almost all the relevant websites, but no success in finding a solution. Thanks in advance for any reply.

PS. Normally all the nodes in a JTree have to same height.

Best regards,

George Song



Do you Yahoo!?
Yahoo! News - Today's headlines



Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!

Reply via email to