简体   繁体   English

父JFrame失去焦点后在TextField中键入时出现JavaFX / Swing线程问题

[英]JavaFX/Swing threading issues when typing in TextField after parent JFrame loses focus

I have a combined Swing/JavaFX application using JDesktopPane and JInternalFrame for MDI and JFXPanel to embed JavaFX fields in the internal frames. 我有一个结合了Swing / JavaFX的应用程序,它使用JDesktopPane和JInternalFrame for MDI和JFXPanel将JavaFX字段嵌入到内部框架中。 This has been working fine up until Java 8u161. 在Java 8u161之前,它一直可以正常工作。 With the update, there are a lot of uncaught exceptions getting thrown when users try to type into text fields, most noticeably after the parent JFrame loses focus. 通过此更新,当用户尝试在文本字段中键入内容时会抛出很多未捕获的异常,最明显的是在父JFrame失去焦点之后。 Any suggestions for workarounds would be greatly appreciated. 任何解决方法的建议将不胜感激。

Sample program: 示例程序:

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TextField;

public class SwingFXTest {

  public static void main(String[] args) {
    SwingUtilities.invokeLater(() -> {
      new SwingFXTest().initAndShowGUI();
    });
  }

  private void initAndShowGUI() {
    JFrame frame = new JFrame("Test 8u161");
    JDesktopPane desktopPane = new JDesktopPane();
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Test Menu");
    menuBar.add(menu);
    JMenuItem menuItem = new JMenuItem("Test Item");
    menuItem.addActionListener(e -> {
      desktopPane.add(createInternalFrame());
    });
    menu.add(menuItem);
    frame.setJMenuBar(menuBar);
    frame.setContentPane(desktopPane);
    frame.setSize(600, 600);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  private JInternalFrame createInternalFrame() {
    JInternalFrame internalFrame = new JInternalFrame();
    internalFrame.setVisible(true);
    internalFrame.setResizable(true);
    internalFrame.setSize(200, 200);
    final JFXPanel fxPanel = new JFXPanel();
    internalFrame.setContentPane(fxPanel);
    Platform.runLater(() -> initFX(fxPanel));
    return internalFrame;
  }

  private void initFX(JFXPanel fxPanel) {
    TextField field = new TextField();
    Group root = new Group(field);
    Scene scene = new Scene(root);
    fxPanel.setScene(scene);
  }

}   

To reproduce the issue: 重现此问题:

Select Test Menu -> Test Item 选择测试菜单->测试项目
Click the text field 单击文本字段
Click outside the application window 在应用程序窗口外单击
Click the text field again 再次单击文本字段
Start typing 开始输入

Sometimes the text doubles (ie typing "test" results in "testtest") and eventually I start getting a number of exceptions. 有时文本加倍(即键入“ test”会导致“ testtest”),最终我开始遇到许多异常。 Example stack trace here . 示例堆栈跟踪在这里

Edit: I am running Windows 10. 编辑:我正在运行Windows 10。

This issue is not reproducible in JDK 8 early-access build (8u172) which is yet to be released. 在尚未发布的JDK 8早期访问版本(8u172)中无法再现此问题。 So please wait for same. 因此,请等待相同。 Also not reproducible in JDK 9 and JDK 10 early-access build . JDK 9JDK 10 抢先体验版中也无法复制。 This issue has already been reported and you can track here: https://bugs.openjdk.java.net/browse/JDK-8195739 Thanks 已经报告了此问题,您可以在这里跟踪: https : //bugs.openjdk.java.net/browse/JDK-8195739谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM