void (PropertyChangeEvent event) { Object oldValue = event.getOldValue(); if (oldValue instanceof TreeModel) { ((TreeModel)oldValue).removeTreeModelListener(listener); } Object newValue = event.getNewValue(); if (newValue instanceof TreeModel) { ((TreeModel)newValue).addTreeModelListener(listener); } }