JComponent (@NotNull String s) { final ActionManager actionManager = ActionManager.getInstance(); final AnAction action = actionManager.getAction(s); if (action == null) { return null; } final Presentation presentation = action.getTemplatePresentation(); if (presentation.getIcon() != null) { return new ActionButton(action, presentation.clone(), GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE, JBUI.emptySize()) { @Override protected void paintButtonLook(Graphics g) { // Don't draw border at the inline button. ActionButtonLook look = getButtonLook(); look.paintBackground(g, this); look.paintIcon(g, this, getIcon()); } }; } final String text = action.getTemplatePresentation().getText(); JLabel result = new JLabel(text) { @Override public void paint(Graphics g) { super.paint(g); final int y = g.getClipBounds().height - getFontMetrics(getFont()).getDescent() + 2; final int width = getFontMetrics(getFont()).stringWidth(getText()); g.drawLine(0, y, width, y); } }; Color color = StartupUiUtil.isUnderDarcula() ? Color.ORANGE : Color.BLUE; result.setForeground(color); result.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent e, int clickCount) { final DataContext context = DataManager.getInstance().getDataContextFromFocus().getResult(); if (context == null) { return false; } final Presentation presentation = new PresentationFactory().getPresentation(action); action.actionPerformed(new AnActionEvent( e, context, GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE, presentation, ActionManager.getInstance(), e.getModifiers() )); return true; } }.installOn(result); return result; }