2

I have a combined Swing/JavaFX application using JDesktopPane and JInternalFrame for MDI and JFXPanel to embed JavaFX fields in the internal frames. This has been working fine up until 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. 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 (i.e. typing "test" results in "testtest") and eventually I start getting a number of exceptions. Example stack trace here.

Edit: I am running Windows 10.

ashhappens
  • 133
  • 1
  • 7
  • Cannot reproduce. Tested on JDK 1.8.0_161 and JDK 9 (build 9+181) on Mac OS X. The stack trace definitely indicates a threading problem though, as there are methods reported on the AWT event thread that should only be called on the FX Application Thread. – James_D Jan 18 '18 at 18:15

1 Answers1

0

This issue is not reproducible in JDK 8 early-access build (8u172) which is yet to be released. So please wait for same. Also not reproducible in JDK 9 and JDK 10 early-access build. This issue has already been reported and you can track here: https://bugs.openjdk.java.net/browse/JDK-8195739 Thanks

Priyanka
  • 115
  • 2