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);
} |