The input field in popup window cannot input Chinese, such as JBTextField, JBTextArea
Answered
I used JBFactory to create a pop-up window with a custom layout, but I found that when I tried to input Chinese in JTextField, my input method tool would go to the lower left corner, and then the JTextField could not display Chinese but could only display the corresponding English letters. I do not know why. The input box in other places can input Chinese information normally, only the pop-up window has problems. I hope someone can help to look at this problem
JPanel popupPanel = new JPanel(new VFlowLayout());
popupPanel.setBorder(BorderFactory.createEmptyBorder(-1,15,-1,15));
JBLabel requestNameLabel = new JBLabel("Request name");
requestNameLabel.setHorizontalAlignment(SwingConstants.LEFT);
JBLabel requestDescLabel = new JBLabel("Request description(Optional)");
requestDescLabel.setHorizontalAlignment(SwingConstants.LEFT);
JBTextField requestNameTextfield = new JBTextField();
requestNameTextfield.setBorder(BorderFactory.createEmptyBorder());
requestNameTextfield.requestFocus();
JBTextArea requestDescTextarea = new JBTextArea();
requestDescTextarea.setPreferredSize(new Dimension(-1,200));
requestDescTextarea.setMargin(new Insets(5, 5, 5, 5));
requestDescTextarea.getEmptyText().setText("Describe your request so you can understand it quickly");
requestNameTextfield.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(@NotNull DocumentEvent documentEvent) {
btnSave.setEnabled(!StrUtil.isBlankOrUndefined(requestNameTextfield.getText()));
}
});
JPanel blankPanel = new JPanel();
blankPanel.setPreferredSize(new Dimension(-1,20));
JPanel blankPanel2 = new JPanel();
blankPanel.setPreferredSize(new Dimension(-1,20));
popupPanel.add(blankPanel);
popupPanel.add(requestNameLabel);
popupPanel.add(requestNameTextfield);
popupPanel.add(blankPanel2);
popupPanel.add(requestDescLabel);
popupPanel.add(requestDescTextarea);
popupPanel.add(toolbar);
IconButton cancelButton = new IconButton("cancel", AllIcons.Actions.Close);
int minSizeWidth = 480;
int minSizeHeight = 400;
JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(popupPanel, requestNameTextfield)
.setTitle("SAVE REQUEST")
.setMovable(true)
.setResizable(true)
.setMinSize(new Dimension(minSizeWidth, minSizeHeight))
.setCancelButton(cancelButton)
.setCancelOnClickOutside(false)
.setFocusable(true)
.setRequestFocus(true)
.createPopup();
RightToolWindow rightToolWindow = ViewHolder.getInstance(project).getRightToolWindow();
int x = (rightToolWindow.getWidth() - minSizeWidth) / 2;
int y = (rightToolWindow.getHeight() - minSizeHeight) / 2;
popup.show(new RelativePoint(rightToolWindow,new Point(x,y)));
First:

Finally:

Please sign in to leave a comment.
Please try to add to the builder chain call a line
@... I tried it, but it didn't work
It works and helps in my environment (macOS 11.3.1), without setNormalWindowLevel() native window appears partially behind popup. Probably
may help you. Do you really need popup here? I'd suggest you to replace JBPopup with DialogWrapper.
@... Thank you for your answer, I found this problem occurred when debugging the plugin, but after I deployed it, everything was normal. I found that when debugging, the newly started project would also have this problem even if it used native components. Maybe this is a bug of Idea? Anyway, thank you for your advice. I'll try later
IDEA Version: 2021.1.1,
OS: MacOS Big Sur 11.2.3