• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

JTree and horizontal lines

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic