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

Reopen of RT-11886, JFXPanel does not work

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P1
    • Resolution: Duplicate
    • Affects Version/s: fx2.0
    • Fix Version/s: None
    • Component/s: javafx
    • Environment:

      both Windows 7 and Mac OS X

      Description

      I am unable to get the JFXPanel to work in the latest build (b21).

      The API documentation example was cutoff, so that was of no help. Instead, I followed Irina's guide (javafx-sdk2.0-ea/docs/javafx/2.0/swing/jfxpub-swing.htm).

      I reproduced her example as closely as possible, and was unable to get it to work (the result was a gray JPanel window with no contents). If you launch the same JavaFX scene in a normal Application it works fine.

      I tested this on Windows and Mac. Surprisingly the results on both were different, but in neither case did it actually work. Full project is attached as a zip, and a screenshot of the results on Windows is attached as well.

      ====== CODE STARTS HERE =====
      package jfxpaneltest;

      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import javafx.application.Application;
      import javafx.application.Launcher;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;
      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;

      public class Main extends Application {
          private static JFXPanel javafxPanel;

          @Override
          public void start(Stage mainStage) {
              System.out.println("start called");
              // This method is invoked on JavaFX thread
              Group root = new Group(new Button("Hi"));
              Scene scene = new Scene(root, Color.ALICEBLUE);
              javafxPanel.setScene(scene);
          }

          public static void initAndShowGUI() {
              JFrame frame = new JFrame("Swing application");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              // Create JavaFX panel.
              javafxPanel = new JFXPanel();
              javafxPanel.setPreferredSize(new Dimension(550, 400));
              frame.getContentPane().add(javafxPanel, BorderLayout.CENTER);

              // Create JavaFX scene.
              Launcher.launch(Main.class, null);

              // Show frame.
              frame.pack();
              frame.setVisible(true);
          }

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {

                  @Override
                  public void run() {
                      initAndShowGUI();
                  }
              });
          }
      }

        Attachments

          Activity

            People

            • Assignee:
              art Artem Ananiev
              Reporter:
              schin Stephen Chin (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: