I have a Tree node. I want an image to be displayed beside the node name when the tree is viewed. How do I go about?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
create an ImageIcon from your image
ImageIcon icon = ….;
(there are a number of ways to do this)
create an instance of DefaultTreeCellRenderer
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
set the leaf icon field of the renderer
renderer.setLeafIcon(icon);
set the tree’s renderer
tree.setCellRenderer(renderer);
if you can’t figure it out try the demo