Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can someone tell me if I disected the JTree UIDelegate paint() method right?  RSS feed

 
shawn larkin
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The lines and expansionIcons get rendered directly in the UIDlegate throught various paint methods. The UIDelegate adds a CellRenderingPane called rendererPane to the referenced JTree. All the nodes(not the lines and the expansionIcon) get rendered on a rendererPane, the nodes are JLabels by default. So essentially, the nodes gets rendered in a container under the lines and expansionIcons, and depending on the user interaction, line and expansionIcon bounds get updated, and the renderingPane receives the updated bound information, repainting itself and shifting the JLabels (nodes) it contains.
I've been trying to get a good grasp of the UIDelegate concept, but the books covering the subject only tackle UIDelegates for components with no subComponents (like a JButton),so I've been going throught everything JTree for the past 3 days and it's become a blur. Please tell me if I got anything wrong, hope this has been interesting reading
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not particularly familiar with the JTree UI delegates, but I have written some UI delegates for other classes.
The best way to figure out what to do is look at the source code for them. You have the source code for the entire JDK in a file called src.zip.
Look at
javax.swing.plaf.TreeUI.java
javax.swing.plaf.basic.BasicTreeUI.java
javax.swing.plaf.metal.MetalTreeUI.java

That will show you exactly how the Swing tree UI delegates are written, and hopefully you can figure out how to get it to do whatever you are trying to do.
Good luck!
 
shawn larkin
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's how I figured this out, looking through the sourcecode from the src.zip file.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!