• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTree image node

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to set an image icon as the tree node, not leaf icon


Thanks
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have pure Swing version ?

Thanks
 
BBird
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic