Changing and Removing the Default Icons in a JTree Component
import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.UIManager; import javax.swing.tree.DefaultTreeCellRenderer; public class Main { public static void main(String[] argv) throws Exception { Icon leafIcon = new ImageIcon("leaf.gif"); Icon openIcon = new ImageIcon("open.gif"); Icon closedIcon = new ImageIcon("closed.gif"); JTree tree = new JTree(); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); renderer.setLeafIcon(leafIcon); renderer.setClosedIcon(closedIcon); renderer.setOpenIcon(openIcon); JFrame f = new JFrame(); f.add(new JScrollPane(tree)); f.setSize(300, 300); f.setVisible(true); } }