• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTree and horizontal lines  RSS feed

 
Mika Leino
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I'm having bit of a problem with my JTree menu applet. The menu should have horizontal lines under each node, and I can't seem to make that happen.
In my code there already is the line

How ever, that only seems to draw the lines between the first level nodes so it looks a bit like this.

Any help would be greatly appreciated.
[ May 21, 2003: Message edited by: Mika Leino ]
 
Bhagya Tangutur
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
extend defautlTreeCellRenderer class and ovveride
getTreeCellRenderComponent() method ,where u can setText in HTML format...which appears your underlines under each node.
public Component getTreeCellRenderComponent(JTree tree,Object value,int row,bololean isSel,boolean hasFocus){
//IMP line(Assuming u have all objects
// as String.else it gives runTime error

setText(<HTML><U>value.toString()</HTML> ;
}

i am not sure whether the above code snippet compiles or not.please check the API.
 
Mika Leino
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the help. Though I'm afraid that it didn't yet solve my problem.
When I added that code snippet in my code the result is that the text of every node is underlined. I need a line which extends from one border of the applet to the other.
I am starting to think that maybe that line should be really in the extended TreeCellRenderer. Is there a way I could make my TreeCellRenderer draw a line at the bottom of each of the tree's cells?
Once again, all help will be greatly appreciated.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
this method
tree.putClientProperty("JTree.lineStyle", "Horizontal");
does group the nodes just as you observed it.
to draw lines with the cell renderer create a line border that paints only the bottom line. there is an appropriate method in BorderFactory.
Chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!