Example usage for com.intellij.openapi.ui.popup JBPopup showInCenterOf

List of usage examples for com.intellij.openapi.ui.popup JBPopup showInCenterOf

Introduction

In this page you can find the example usage for com.intellij.openapi.ui.popup JBPopup showInCenterOf.

Prototype

void showInCenterOf(@NotNull Component component);

Source Link

Document

Shows the popup in the center of the specified component.

Usage

From source file:com.intellij.ide.favoritesTreeView.TaskDefaultFavoriteListProvider.java

License:Apache License

private void showNotePopup(Project project, final DnDAwareTree tree, final Consumer<String> after,
        final String initText) {
    final JTextArea textArea = new JTextArea(3, 50);
    textArea.setFont(UIUtil.getTreeFont());
    textArea.setText(initText);// w w w .  j av  a  2s .  co m
    final JBScrollPane pane = new JBScrollPane(textArea);
    final ComponentPopupBuilder builder = JBPopupFactory.getInstance()
            .createComponentPopupBuilder(pane, textArea).setCancelOnClickOutside(true)
            .setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish")
            .setTitle("Comment").setMovable(true).setRequestFocus(true).setResizable(true).setMayBeParent(true);
    final JBPopup popup = builder.createPopup();
    final JComponent content = popup.getContent();
    final AnAction action = new AnAction() {
        @Override
        public void actionPerformed(AnActionEvent e) {
            popup.closeOk(e.getInputEvent());
            unregisterCustomShortcutSet(content);
            after.consume(textArea.getText());
        }
    };
    action.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, content);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            popup.showInCenterOf(tree);
        }
    }, ModalityState.NON_MODAL, project.getDisposed());
}