void (@NotNull SimpleColoredComponent component) { new LinkMouseListenerBase<Object>() { @Override protected @Nullable Object getTagAt(@NotNull MouseEvent e) { return ((SimpleColoredComponent)e.getSource()).getFragmentTagAt(e.getX()); } @Override protected void handleTagClick(@Nullable Object tag, @NotNull MouseEvent event) { if (tag != null) { if (tag instanceof Consumer consumer) { //noinspection unchecked consumer.consume(event); } else if (tag instanceof java.util.function.Consumer consumer) { //noinspection unchecked consumer.accept(event); } else { ((Runnable)tag).run(); } } } }.installOn(component); }