package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;

public final class MainPanel extends JPanel {
    private final JCheckBox folderCheck = new JCheckBox("OpenIcon, ClosedIcon");
    private final JCheckBox leafCheck   = new JCheckBox("LeafIcon");
    //private final Icon emptyIcon = new EmptyIcon();
    private final JTree tree = new JTree();
    public MainPanel() {
        super(new BorderLayout());

        for (int i = 0; i < tree.getRowCount(); i++) {
            tree.expandRow(i);
        }

        DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
        renderer.setOpenIcon(null);
        renderer.setClosedIcon(null);
        renderer.setLeafIcon(null);
        allNodesChanged(tree);

        folderCheck.addActionListener(e -> {
            DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) tree.getCellRenderer();
            if (((JCheckBox) e.getSource()).isSelected()) {
                r.setOpenIcon(r.getDefaultOpenIcon());
                r.setClosedIcon(r.getDefaultClosedIcon());
            } else {
                r.setOpenIcon(null);
                r.setClosedIcon(null);
            }
            allNodesChanged(tree);
        });
        leafCheck.addActionListener(e -> {
            DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) tree.getCellRenderer();
            if (((JCheckBox) e.getSource()).isSelected()) {
                r.setLeafIcon(r.getDefaultLeafIcon());
            } else {
                r.setLeafIcon(null);
            }
            allNodesChanged(tree);
        });

//         tree.setCellRenderer(new DefaultTreeCellRenderer() {
//             @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
//                 super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
//                 if (leaf) {
//                     if (!leafCheck.isSelected()) {
//                         setIcon(null);
//                     } else {
//                         setIcon(getDefaultLeafIcon());
//                     }
//                 } else {
//                     if (!folderCheck.isSelected()) {
//                         setIcon(null);
//                     } else {
//                         if (expanded) {
//                             setIcon(getDefaultOpenIcon());
//                         } else {
//                             setIcon(getDefaultClosedIcon());
//                         }
//                     }
//                 }
//                 return this;
//             }
//         });

        JPanel np = new JPanel();
        np.add(folderCheck);
        np.add(leafCheck);

        add(np, BorderLayout.NORTH);
        add(new JScrollPane(tree));
        setPreferredSize(new Dimension(320, 240));
    }
    private static void allNodesChanged(JTree tree) {
        DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        Collections.list((Enumeration<?>) root.preorderEnumeration()).stream()
            .filter(TreeNode.class::isInstance).map(TreeNode.class::cast)
            .forEach(model::nodeChanged);
//         Enumeration<?> e = root.preorderEnumeration();
//         while (e.hasMoreElements()) {
//             model.nodeChanged((TreeNode) e.nextElement());
//         }
        //tree.revalidate();
        //tree.repaint();
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
// class EmptyIcon implements Icon, Serializable {
//     @Override public void paintIcon(Component c, Graphics g, int x, int y) { /* Empty icon */ }
//     @Override public int getIconWidth() { return 0; }
//     @Override public int getIconHeight() { return 0; }
// }

@@ -241,255 +241,8 @@
 ate 
-final JCheckBox folderCheck = new JCheckBox(%22OpenIcon, ClosedIcon%22);%0A    private final JCheckBox leafCheck   = new JCheckBox(%22LeafIcon%22);%0A    //private final Icon emptyIcon = new EmptyIcon();%0A    private final JTree tree = new JTree();%0A    public 
 Main
@@ -283,24 +283,58 @@
 Layout());%0A%0A
+        JTree tree = new JTree();%0A
         for 
@@ -418,16 +418,99 @@
      %7D%0A%0A
+        // TEST: Icon emptyIcon = null;%0A        Icon emptyIcon = new EmptyIcon();%0A%0A
         
@@ -615,36 +615,41 @@
 rer.setOpenIcon(
-null
+emptyIcon
 );%0A        rende
@@ -658,36 +658,41 @@
 r.setClosedIcon(
-null
+emptyIcon
 );%0A        rende
@@ -699,36 +699,41 @@
 rer.setLeafIcon(
-null
+emptyIcon
 );%0A        allNo
@@ -747,24 +747,95 @@
 ged(tree);%0A%0A
+        JCheckBox folderCheck = new JCheckBox(%22OpenIcon, ClosedIcon%22);%0A
         fold
@@ -1178,28 +1178,33 @@
 setOpenIcon(
-null
+emptyIcon
 );%0A         
@@ -1222,28 +1222,33 @@
 tClosedIcon(
-null
+emptyIcon
 );%0A         
@@ -1294,24 +1294,82 @@
 %0A        %7D);
+%0A%0A        JCheckBox leafCheck = new JCheckBox(%22LeafIcon%22);
 %0A        lea
@@ -1656,20 +1656,25 @@
 eafIcon(
-null
+emptyIcon
 );%0A     
@@ -3621,63 +3621,8 @@
   %7D%0A
-        //tree.revalidate();%0A        //tree.repaint();%0A
     
@@ -4430,19 +4430,17 @@
     %7D%0A%7D%0A
-// 
+%0A
 class Em
@@ -4466,28 +4466,11 @@
 Icon
-, Serializable %7B%0A// 
+ %7B%0A
     
@@ -4561,19 +4561,16 @@
 on */ %7D%0A
-// 
     @Ove
@@ -4602,32 +4602,41 @@
 idth() %7B
- return 0; %7D%0A// 
+%0A        return 2;%0A    %7D%0A
     @Ove
@@ -4669,16 +4669,24 @@
 ight() %7B
+%0A       
  return 
@@ -4687,16 +4687,17 @@
 eturn 0;
+%0A   
  %7D%0A
-// 
 %7D%0A

use EmptyIcon instead of DefaultTreeCellRenderer#setLeafIcon(null)