aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTree image node Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree image node" Watch "JTree image node" New topic
Author

JTree image node

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
I want to set an image icon as the tree node, not leaf icon


Thanks
BBird
Greenhorn

Joined: Nov 01, 2004
Posts: 6
final Image pic0 = new Image(display, "pic0.jpg");
final Image pic1 = new Image(display, "pic2.jpg");
final Image pic2 = new Image(display, "pic2.jpg");

final Tree x = new Tree(sShell, SWT.MULTI | SWT.BORDER);
x.setSize(140, 180);
x.setLocation(10, 10);

TreeItem root = new TreeItem(x, SWT.NONE);
root.setText("My Album");
root.setImage(pic0);

TreeItem t1 = new TreeItem(root, SWT.NONE);
t1.setText("Sub Album 1");
t1.setImage(pic1);

TreeItem t2 = new TreeItem(root, SWT.NONE);
t2.setText("Sub Album 2");
t2.setImage(pic2);
------------------

Hope this helps...
Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
Do you have pure Swing version ?

Thanks
BBird
Greenhorn

Joined: Nov 01, 2004
Posts: 6
Oops!....sorry,...i am dealling with SWT...
Well, by the way, I am developping the application like ACDSee and I am two-day struck on loading image file.
I mean....dynamic loadding some pix from the folder located on C:\ or A:\, for example, ...Do you have any idea?

Thanx,
Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
About image node in JTree.
I have found an acceptable , even not perfect, solution. The key point is ,TreeCellRender is a subclass of JLabel, that mean, we can use simple setIcon, setText function of JLabel. If we want more control, we should think how to build our custom JLabel.

about load the image.
Actually I can't fully understand your question. Maybe the problem is , the image path can't be found. I guess you are using Eclipse, if this, loading image will be easy. you can use Eclipse VEP to add icon to JLabel.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree image node
 
Similar Threads
Custom JTree addings
Problem with jsf tree
Whether tag handlers are needed in creating a t:tree component
null pointer exception while closing a node of jtree
How to work with t:tree component