void (Collection<? extends SettingsEditorFragment<Settings, ?>> fragments) { for (SettingsEditorFragment<Settings, ?> fragment : fragments) { JComponent component = fragment.getEditorComponent(); if (component == null) continue; FocusListener listener = new FocusListener() { @Override public void focusGained(FocusEvent e) { } @Override public void focusLost(FocusEvent e) { checkGotIt(fragment); } }; component.addFocusListener(listener); Disposer.register(fragment, () -> component.removeFocusListener(listener)); } }