Can't type in a popup with JTextField

Answered

Hi,

The purpose of this plugin is to simply create a popup with JTextField so that I can type something on it. However, The JTextField is not focusable and nothing can be typed on it. A little bit of information, I am using Windows 10 and Intellij 2020.1 version

Any thoughts about this? Thanks. 

0
4 comments

Chris, sorry but it's hard to guess the problem with no information about your current implementation. You may consider providing some minimal reproducible example so it'd be easier to debug the problem.

0
Hi Jakub:
Here is my code:
JTextField myTextField = new JTextField("Here I am", 20);

JComponent myPanel = new JPanel();
myPanel.add(myTextField);

myTextField.setEditable(true);
myTextField.setEnabled(true);
myTextField.requestFocus();
JBPopupFactory.getInstance().createComponentPopupBuilder(myPanel, myTextField)
.createPopup().showInBestPositionFor(e.getData(PlatformDataKeys.EDITOR));


And it will show a popup with a textfield in it as shown in the above picture. However, I can't type anything into the textfield
and my mouse cursor can't be focused in the textfield.


In this case, what is wrong with my JTextField?? Any thoughts will be appreciated. Or a working code with JTextField that is editable is more than welcome to share.
Thanks!
0

It's a common Swing issue, however, you can easily resolve it by setting the following flags:

JBPopupFactory.getInstance()
.createComponentPopupBuilder(myPanel, myTextField)
.setFocusable(true)
.setRequestFocus(true)
.createPopup()
.showInBestPositionFor(editor)

 

0

Gosh, you just save my life. Thanks

0

Please sign in to leave a comment.