View Single Post
  #10 (permalink)  
Old 01-21-2009, 04:25 AM
hardwired's Avatar
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
Actually, the example I used in my implementation was it #2 above.
Sorry, I never would have known.

One of the difficulties with the design you have adopted is the use of the renderer component for editing. Adding a new ItemListener at each edit will cause trouble in time. Add this line in your CheckBoxNodeEditor class and click on a few checkBoxes in the tree to see:
Code:
            if (editor instanceof JCheckBox)
            {
                ((JCheckBox)editor).addItemListener(itemListener);
                // There is only one editor so only one listener is
                // required. Here's a telltale:
                System.out.println("editor ItemListener count = " +
                       editor.getListeners(ItemListener.class).length);
            }
You can try this to limit the insanity:
Code:
            if (editor instanceof JCheckBox)
            {
                JCheckBox cb = (JCheckBox)editor;
                if(cb.getListeners(ItemListener.class).length == 0)
                {
                    ((JCheckBox)editor).addItemListener(itemListener);
                }
                // There is only one editor so only one listener is
                // required. Here's a telltale:
                System.out.println("editor ItemListener count = " +
                       editor.getListeners(ItemListener.class).length);
            }
Reply With Quote