void (Component component) { initCopyFromMenu(); DefaultActionGroup group = new DefaultActionGroup(); JBTreeTraverser<Component> traverser = JBTreeTraverser.<Component>of( o -> o instanceof JMenu ? new Component[] { new TitledSeparator(((JMenu)o).getText()), ((JMenu)o).getPopupMenu()} : o instanceof JPopupMenu ? ((JPopupMenu)o).getComponents() : null) .withRoot(myCopyFromMenu); for (Component c : traverser.traverse(TreeTraversal.LEAVES_DFS)) { if (c instanceof JSeparator) { group.addSeparator(); } else if (c instanceof TitledSeparator) { group.addSeparator(((TitledSeparator)c).getText()); } else if (c instanceof JMenuItem) { group.add(new DumbAwareAction(((JMenuItem)c).getText(), "", ObjectUtils.notNull(((JMenuItem)c).getIcon(), EmptyIcon.ICON_16)) { @Override public void actionPerformed(@NotNull AnActionEvent e) { ((JMenuItem)c).doClick(); } }); } } int maxRows = group.getChildrenCount() > 17 ? 15 : -1; DataContext dataContext = DataManager.getInstance().getDataContext(component); JBPopupFactory.getInstance().createActionGroupPopup( null, group, dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false, null, maxRows, null, "popup@TabbedLanguageCodeStylePanel") .showUnderneathOf(component); }