Java 为什么可以';t我在IntelliJ插件的文本字段中键入';什么是弹出窗口?
我正在尝试制作一个简单的插件。我只想创建一个可以输入的弹出窗口。现在,弹出窗口出现了,但我无法集中精力或在文本字段中键入内容。下面是我如何创建弹出窗口的Java 为什么可以';t我在IntelliJ插件的文本字段中键入';什么是弹出窗口?,java,swing,popup,intellij-plugin,Java,Swing,Popup,Intellij Plugin,我正在尝试制作一个简单的插件。我只想创建一个可以输入的弹出窗口。现在,弹出窗口出现了,但我无法集中精力或在文本字段中键入内容。下面是我如何创建弹出窗口的 public void actionPerformed(AnActionEvent e) { JTextField myTextField = new JTextField("Here I am", 20); JComponent myPanel = new JPanel(); myPanel.add(myTextFie
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()返回true。我不知道到底是什么问题,但我用这一行创建了弹出窗口,从而解决了这个问题
JBPopupFactory.getInstance().createComponentPopupBuilder(panel, textField).createPopup().showInBestPositionFor(e.getData(PlatformDataKeys.EDITOR));
这使弹出窗口居中。通过调用组件PopubBuilder.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);
}