public Component getTreeCellRendererComponent ( JTree tree , Object value , boolean selected , boolean expanded , boolean leaf , int row , boolean hasFocus ) { String stringValue = tree . convertValueToText ( value , selected , expanded , leaf , row , hasFocus ) ; /** Set the text. */ this . setText ( stringValue ) ; /** Tooltips used by the tree. */ // this.setToolTipText(stringValue); /** Set the image. */ /** if(expanded) setIcon(expandedIcon); else if(!leaf) setIcon(collapsedIcon); else setIcon(null); */ /** Set the color and the font based on the SampleData userObject. */ NodeData userObject = ( NodeData ) ( ( DefaultMutableTreeNode ) value ) . getUserObject ( ) ; /** Update the selected flag for the next paint. */ this . selected = selected ; if ( selected ) this . setOpaque ( true ) ; else this . setOpaque ( false ) ; return this ; }
This is messaged from JTree whenever it needs to get the size of the component or it wants to draw it . This attempts to set the font based on value which will be a TreeNode .