Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8144504

Multiple SwingNode in JFXPanel in JFrame Cause Extreme Performance Degradation

XMLWordPrintable

    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      No special configuration requirements. Also confirmed on OS X 10.11.1

      A DESCRIPTION OF THE PROBLEM :
      Placing 2+ SwingNode objects in a JFXPanel contained in a JFrame causes the application to come to a crawl upon one of the JComponents within the SwingNodes receiving focus.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Create a JFrame window
      2) Put a JFXPanel in the window
      3) Create a GridPane
      4) Create two SwingNode objects, each containing a JToggleButton
      5) Place the SwingNode objects on the GridPane
      6) Set the JFXPanel scene to a scene with the GridPane
      7) Show the JFrame
      8) Click one of the toggle buttons
      9) Click the toggle button again

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Application toggles and untoggles the button
      ACTUAL -
      Application toggles the button after a short delay, and then freezes.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.embed.swing.SwingNode;
      import javafx.scene.Scene;
      import javafx.scene.control.ToggleButton;
      import javafx.scene.layout.ColumnConstraints;
      import javafx.scene.layout.GridPane;

      public class SwingNodeTest {
          private static Scene createScene(JComponent button1, JComponent button2) {
              GridPane pane = new GridPane();
              pane.getColumnConstraints().add(new ColumnConstraints(100));
              pane.getColumnConstraints().add(new ColumnConstraints(200));

              SwingNode node1 = new SwingNode();
              // Best practice to call SwingNode->setContent(...) on the EDT, but doesn't make
              // a difference for the test.
              node1.setContent(button1);
              pane.add(node1, 0, 0);

              ToggleButton node2 = new ToggleButton("2");
              // Commenting out the above line and uncommenting the below lines cause EXTREME
              // Performance degradation.
      // SwingNode node2 = new SwingNode();
      // node2.setContent(button2);
              pane.add(node2, 1, 0);

              return new Scene(pane);
          }

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      JFrame frame = new JFrame();
                      JFXPanel panel = new JFXPanel();
                      frame.setSize(800, 600);
                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      frame.setContentPane(panel);
                      frame.setVisible(true);

                      JButton button1 = new JButton("1");
                      JToggleButton button2 = new JToggleButton("2");

                      Platform.runLater(new Runnable() {
                          @Override
                          public void run() {
                              final Scene scene = createScene(button1, button2);
                              panel.setScene(scene);
                          }
                      });
                  }
              });
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Restricting SwingNode usage within JFXPanels under JFrames is the only workaround known ATM. This restricts our ability to use JavaFX, as we are heavily invested in custom Swing components/containers.

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: