3 Replies Latest reply: May 13, 2012 12:17 PM by 935688 RSS

    How to use Dual Monitor in JavaFX2 ?

    935688
      I want to use Dual Monitor (Screen Device) in JavaFX2 Application.

      In Java2SE , JFrame take GraphicsConfiguration arg.

      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice[] gs = ge.getScreenDevices();
      GraphicsDevice gd = gs[0];
      GraphicsConfiguration gc = gd.getDefaultConfiguration();
      JFrame jf = new JFrame(gc);
      ......


      How can I use Dual Monitor in JavaFX2 ?

      Thank you.
        • 1. Re: How to use Dual Monitor in JavaFX2 ?
          jsmith
          There is a Screen class:
          http://docs.oracle.com/javafx/2/api/javafx/stage/Screen.html
          Hopefully you can find the information you need there.
          If not, post back with the JavaFX code you tried and couldn't get to work.

          I just have a single monitor on my current PC, so I can't test anything out to provide sample code.
          • 2. Re: How to use Dual Monitor in JavaFX2 ?
            JohnHendrikx
            Here is a piece of code from my program that sets up a stage to be on a certain screen (given by screenNumber):
              private void setupStageLocation(Stage stage, int screenNumber) {
                ObservableList<Screen> screens = Screen.getScreens();
                Screen screen = screens.size() <= screenNumber ? Screen.getPrimary() : screens.get(screenNumber);
            
                Rectangle2D bounds = screen.getBounds();
                boolean primary = screen.equals(Screen.getPrimary());    // WORKAROUND: this doesn't work nice in combination with full screen, so this hack is used to prevent going fullscreen when screen is not primary
            
                if(primary) {
                  stage.setX(bounds.getMinX());
                  stage.setY(bounds.getMinY());
                  stage.setWidth(bounds.getWidth());
                  stage.setHeight(bounds.getHeight());
                  stage.setFullScreen(true);
                }
                else {
                  stage.setX(bounds.getMinX());
                  stage.setY(bounds.getMinY());
                  stage.setWidth(bounds.getWidth());
                  stage.setHeight(bounds.getHeight());
                  stage.toFront();
                }
              }
            • 3. Re: How to use Dual Monitor in JavaFX2 ?
              935688
              jsmith, john16384 , Thank you for reply.

              I understand about "javafx.stage.Screen" !!

              Regards.