dcsimg
How can I show two icons on a JTree entry?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   bernard_poulin
Posted On:   Monday, March 26, 2001 03:46 PM

I know the TreeCellRenderer uses a JLabel component to draw the icon and the text part.

What would be the "cleanest" way to draw an extra icon?

thanks,

Bernard

How can I show two icons on a JTree entry?

Posted By:   Scott_Stanchfield  
Posted On:   Wednesday, April 25, 2001 08:10 AM

Create your own renderer that uses a JPanel with two labels in it.

Nest the labels using a BorderLayout, something like


JPanel p = new JPanel(new BorderLayout());
JLabel iconOnly = new JLabel(someIcon);
JLabel iconAndText = new JLabel(someText,anotherIcon);
p.add(iconOnly, BorderLayout.WEST);
p.add(iconAndText, BorderLayout.CENTER);


See the Swing FAQs for how to write renderers

Re: How can I show two icons on a JTree entry?

Posted By:   Sandip_Chitale  
Posted On:   Wednesday, March 28, 2001 11:43 PM

Implement the javax.swing.Icon Interface in a class which delegates the painting to two other Icons (javax.swing.ImageIcons say !). It should also report the correct height (max height of the two delgates)and width (sum of the widths of two delegates). (This assumes you want to show two images side by side).
Now set an instance of this Icon implementation as the icon of the TreeCellRendeder JLabel using setIcon().


In fact you can generalize this to paint a series of images side-by-side or grid or whatever.

About | Sitemap | Contact