Why can't I type in the JTextField of my popup?

All I'm trying to do is create a popup and type in it.  The popup appears, but I can't type in it, or even give it focus.  If I click on it,
and then type, the text appears in the active editor.

public void actionPerformed(AnActionEvent e) {
    JTextField myTextField = new JTextField("Here I am", 20);
    JComponent myPanel = new JPanel();
    myPanel.add(myTextField);
    JBPopupFactory.getInstance().createComponentPopupBuilder(myPanel, myTextField).createPopup().show(myPanel);
}

6 comments
Comment actions Permalink

Hello Adam,

this may or may not be the issue:

if you use Linux Gnome, check your settings for Window focus.

most likely it is set to "mouse" or "sloppy" mode.

It is easy to check: when your popup appears, before typing in the textbox, make sure the cursor and mouse pointer are within the textbox. Does this work?

0
Comment actions Permalink

I am using Linux Gnome (Ubuntu 14.04), but clicking on it doesn't do anything.  If I click on the textfield, and type, it keeps typing in the editor beneath the popup.  Could it matter that the popup is appearing in the top right corner?  I didn't bother setting it's location yet.

0
Comment actions Permalink

check if the mouse pointer stays over the textbox as you type.

Gnome mouse/sloppy mode means: once mouse moves away, Gnome promptly sets focus to the window where the mouse pointer is.

try to click on textbox and keep the mouse right there as you type - even if this obscures the textbox.

Or try to change Gnome settings for Window focus to "click"

0
Comment actions Permalink

That's not it.  I get the same behavior even if the mouse stays over the text field.

0
Comment actions Permalink

I fixed it by switching from show(panel) to showInBestPositionFor(e.getData(PlatformDataKeys.EDITOR)).  This centered the popup.  Maybe it was in an illegal position before.  The full expression is

        JBPopupFactory.getInstance().createComponentPopupBuilder(panel, textField).createPopup().showInBestPositionFor(e.getData(PlatformDataKeys.EDITOR));

0
Comment actions Permalink

Just created the popup with this line instead,

JBPopupFactory.getInstance().createComponentPopupBuilder(panel, textField).createPopup().showInBestPositionFor(e.getData(PlatformDataKeys.EDITOR));

0

Please sign in to leave a comment.