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

set fullscreen in swing and embed javafx doesn't display anything

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • fx2.0
    • javafx
    • None
    • Windows

      Cause the fullscreen option doesn't support setting the resolution and swing does,
      i tried to set the resolution in swing and then embed the javafx application but it doesn't show anything..



      package hh;
       
      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.image.Image;
      import javafx.scene.image.ImageView;
       
      import javax.swing.*;
      import java.awt.*;
       
      public class Test extends JFrame {
       
          private static JFXPanel javafxPanel;
          private ScreenManager screen = new ScreenManager(this);
          private static Scene scene;
          private static DisplayMode displayMode;
       
          public static void createScene() {
              Group root = new Group();
              scene = new Scene(root);
       
              Group content = new Group();
              ImageView bg1 = new ImageView();
              bg1.setImage(new Image(Test.class.getResourceAsStream("/background.jpg")));
              content.getChildren().add(bg1);
       
              root.getChildren().add(content);
              // add scene to panel
              javafxPanel.setScene(scene);
          }
       
          public static void main(String[] args) {
              new Test();
          }
       
          public Test() {
       
              GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
              int bitDepth = env.getDefaultScreenDevice().getDisplayMode().getBitDepth();
              displayMode = new DisplayMode(1024, 768, bitDepth, DisplayMode.REFRESH_RATE_UNKNOWN);
       
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      JFrame frame = new JFrame("test");
                      frame.setResizable(false);
                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
                      // create javafx panel
                      javafxPanel = new JFXPanel();
                      javafxPanel.setPreferredSize(new Dimension(550, 400));
       
                      // create JavaFX scene
                      Platform.runLater(new Runnable() {
                          public void run() {
                              createScene();
                          }
                      });
       
                      frame.setContentPane(javafxPanel);
                      screen.setFullScreen(displayMode);
       
                      frame.pack();
                      frame.setLocationRelativeTo(null);
                      frame.setVisible(true);
                  }
              });
       
          }
      }
       
       
      ------------------------------
       
      package hh;
       
      import javax.swing.*;
      import java.awt.*;
       
      public class ScreenManager {
       
          private GraphicsDevice device;
          private JFrame window;
       
          public ScreenManager(JFrame window) {
              this.window = window;
              GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
              device = environment.getDefaultScreenDevice();
          }
       
          public void setFullScreen(DisplayMode displayMode) {
       
              this.window.setVisible(false);
              this.window.dispose();
              this.window.setUndecorated(true);
              this.window.setResizable(false);
       
              device.setFullScreenWindow(this.window);
              if (displayMode != null &&
                      device.isDisplayChangeSupported()) {
                  try {
                      device.setDisplayMode(displayMode);
                  } catch (Exception ex) {
                      ex.printStackTrace();
                  }
              }
          }
       
          public Window getFullScreenWindow() {
              return device.getFullScreenWindow();
          }
       
          public void restoreScreen() {
              Window window = device.getFullScreenWindow();
              if (this.window != null) {
                  this.window.dispose();
              }
              device.setFullScreenWindow(null);
              Dimension dim = new Dimension(1024, 768);
              this.window.setResizable(false);
              this.window.setPreferredSize(dim);
              this.window.setSize(dim);
              this.window.setLocationRelativeTo(null);
              this.window.setUndecorated(false);
          // this.window.setTitle(g.trans("title"));
              this.window.setVisible(true);
          }
       
      }

            Unassigned Unassigned
            mortiasjfx mortias (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Imported: