为什么我不能在 IntelliJ 插件弹出窗口的文本字段中输入内容?
Why can't I type in the text field of my IntelliJ plugin's popup?
我正在尝试制作一个简单的插件。我只想创建一个我可以输入的弹出窗口。现在,出现了弹出窗口,但我无法专注于它或在文本字段中输入内容。这是我创建弹出窗口的方式。
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);
}
需要说明的是,弹出窗口与其 JPanel 和 JTextField 一起出现,但我无法专注于它或无法在其中键入内容。此外,myPanel.isEditable() returns 正确。
我不知道到底是什么问题,但我通过使用此行创建弹出窗口来修复它。
JBPopupFactory.getInstance().createComponentPopupBuilder(panel, textField).createPopup().showInBestPositionFor(e.getData(PlatformDataKeys.EDITOR));
这使弹出窗口居中。
通过调用 ComponentPopupBuilder.setRequestFocus(true)
我解决了这个问题。
我正在尝试制作一个简单的插件。我只想创建一个我可以输入的弹出窗口。现在,出现了弹出窗口,但我无法专注于它或在文本字段中输入内容。这是我创建弹出窗口的方式。
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);
}
需要说明的是,弹出窗口与其 JPanel 和 JTextField 一起出现,但我无法专注于它或无法在其中键入内容。此外,myPanel.isEditable() returns 正确。
我不知道到底是什么问题,但我通过使用此行创建弹出窗口来修复它。
JBPopupFactory.getInstance().createComponentPopupBuilder(panel, textField).createPopup().showInBestPositionFor(e.getData(PlatformDataKeys.EDITOR));
这使弹出窗口居中。
通过调用 ComponentPopupBuilder.setRequestFocus(true)
我解决了这个问题。