net.alantea.swing.tree.TreeObjectCellRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swingplus Show documentation
Show all versions of swingplus Show documentation
Addons over swing package.
The newest version!
package net.alantea.swing.tree;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
public class TreeObjectCellRenderer extends DefaultTreeCellRenderer
{
private static final long serialVersionUID = 1L;
TreeObjectCellRenderer()
{
}
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus)
{
JComponent component = (JComponent) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,hasFocus);
component.setOpaque(true);
Object o = ((DefaultMutableTreeNode) value).getUserObject();
if (o instanceof TreeObject)
{
TreeObject> object = (TreeObject>)o;
if (object.getImage() != null)
{
((JLabel) component).setIcon(new ImageIcon(object.getImage()));
}
((JLabel) component).setText(object.getName());
}
else
{
((JLabel) component).setText(o.toString());
}
if (selected)
{
component.setBackground(tree.getBackground().brighter());
}
else
{
component.setBackground(tree.getBackground());
}
return component;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy