View Javadoc
1 package xdoclet.gui.swing; 2 3 import javax.swing.ImageIcon; 4 import javax.swing.JLabel; 5 import javax.swing.JTree; 6 import javax.swing.tree.DefaultTreeCellRenderer; 7 8 import java.awt.Component; 9 import java.awt.Image; 10 11 import java.beans.BeanInfo; 12 import java.beans.IntrospectionException; 13 import java.beans.Introspector; 14 15 /*** 16 * Renders a tree cell using information from a bean's BeanInfo. 17 * 18 * @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a> 19 * @version $Revision: 1.4 $ 20 */ 21 class BeanTreeCellRenderer extends DefaultTreeCellRenderer { 22 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, 23 boolean leaf, int row, boolean hasFocus) { 24 // Let the superclass do the dirty work. 25 JLabel result = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 26 27 try { 28 BeanInfo beanInfo = Introspector.getBeanInfo(value.getClass()); 29 30 Image image = beanInfo.getIcon(BeanInfo.ICON_COLOR_16x16); 31 32 if (image != null) { 33 result.setIcon(new ImageIcon(image)); 34 } 35 36 result.setText(beanInfo.getBeanDescriptor().getName()); 37 } catch (IntrospectionException e) { 38 e.printStackTrace(); //To change body of catch statement use Options | File Templates. 39 } 40 41 return result; 42 } 43 }

This page was automatically generated by Maven