void (@NotNull JComponent component, @NotNull BooleanSupplier action) { ActionListener listener = component.getActionForKeyStroke(ENTER); component.registerKeyboardAction(event -> { if (!action.getAsBoolean() && listener != null) { // perform previous action if the specified action is failed, // it is needed to expand/collapse a tree node listener.actionPerformed(event); } }, ENTER, JComponent.WHEN_FOCUSED); }