문제

Below is the code i have created a Jtree with root Node "Data Generation..

rootNode = new DefaultMutableTreeNode("Data Generation");
treeModel =new DefaultTreeModel(rootNode);
tree = new JTree(treeModel);            
tree.setEditable(true);

I have changed the icon images for the leaf node

childNode=new DefaultMutableTreeNode(existingtagnames.get(len).toString());
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
ImageIcon imageIcon = new ImageIcon(Generate_Explorer.class.getResource("/org/qmon/generate/Images/Leaf Node.png"));
renderer.setLeafIcon(imageIcon);
tree.setCellRenderer(renderer);

I dont know how to do for the Root node.. i searched in the internet but unable to find it.

Thanks in advance.

도움이 되었습니까?

해결책

If you use these two methods on the renderer, it should set your icon on non-leaf nodes.

setClosedIcon(Icon newIcon)

setOpenIcon(Icon icon)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top