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

JFXPanel does not work in fullscreen mode

XMLWordPrintable

      We would like to use some pieces of JavaFX in our existing Swing application. Porting everything to JavaFX is not an option right now. The application is fullscreen which seems to cause the Swing integration to fail. I've created a small sample that reproduces the problem.

      I have a simple JFXPanel with a WebView (tried to replace it with a Button and the result is the same) in a JFrame. As long as the JFrame is not set in fullscreen mode everything works fine, but when I add the following code the area were the JFXPanel is remains grey.

              GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
              GraphicsDevice gs = ge.getDefaultScreenDevice();
              gs.setFullScreenWindow(frame);

      For completness I am adding the entire code that I used to reproduce the problem.

      import javafx.application.Application;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.web.WebEngine;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;

      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;
      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import java.awt.GraphicsDevice;
      import java.awt.GraphicsEnvironment;

      public class MainTest extends Application {

          private static JFXPanel javafxPanel;

          private void initAndShowFrame() {
              JFrame frame = new JFrame("JxBrowser");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              javafxPanel = new JFXPanel();
              javafxPanel.setPreferredSize(new Dimension(1024,800));

              frame.getContentPane().add(javafxPanel, BorderLayout.CENTER);

              // Create JavaFX scene.
              Application.launch(MainTest.class, null);

              frame.setVisible(true);
              frame.setSize(new Dimension(1024, 800));

              // if these following 3 lines are commented out, everything works fine.
              GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
              GraphicsDevice gs = ge.getDefaultScreenDevice();
              gs.setFullScreenWindow(frame);
          }

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      MainTest jxBrowser = new MainTest();
                      jxBrowser.initAndShowFrame();
                  }
              });
          }


          public void start(final Stage stage) throws Exception {
              //Create the scene and the stage

              Group root = new Group();
              final Scene scene = new Scene(root);
              final WebEngine webEngine = new WebEngine();
              WebView webView = new WebView(webEngine);
              webEngine.load("http://www.oracle.com");
              root.getChildren().add(webView);

              // Add scene to panel
              javafxPanel.setScene(scene);
          }

      }

            art Artem Ananiev (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: