void (@NotNull Tree tree, @NotNull Class<?> listenerClass) { TreeSelectionListener[] listeners = tree.getTreeSelectionListeners(); for (TreeSelectionListener listener : listeners) { if (listenerClass.isInstance(listener)) { tree.removeTreeSelectionListener(listener); } } }