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

JFXPanel applies wrong screen scaling

    XMLWordPrintable

Details

    • x86_64
    • windows_10
    • Verified

    Description

      ADDITIONAL SYSTEM INFORMATION :
      two screens with different scaling configurations (primary 125%, secondary 100%)

      A DESCRIPTION OF THE PROBLEM :
      JFXPanel always refers to the transformation scale of the default screen device, instead of referring to the scale of the screen device where it is presented. The result is, that the UI is sometimes extremely blurry.

      In updateComponentSize() and paintComponent(Graphics g) the following code is called:
      newScaleFactorX = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX();

      Changing the code to the following corrects the behavior for me:
      newScaleFactorX = getGraphicsConfiguration().getDefaultTransform().getScaleX();

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Move window containing JFXPanel onto secondary screen, which has different scale than the primary screen.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Content of JFXPanel is properly scaled according to secondary screen.
      ACTUAL -
      Content of JFXPanel is scaled according to primary screen.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Scene;
      import javafx.scene.web.WebView;

      public class JFXPanelDemo {

        public static void main(String[] args) {
          SwingUtilities.invokeLater(() -> initAwt());
        }

        private static void initAwt() {
          JFrame frame = new JFrame("JFXPanelDemo");
          final JFXPanel fxPanel = new JFXPanel();
          frame.add(fxPanel);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(600, 400);
          frame.setVisible(true);
          Platform.runLater(() -> initFx(fxPanel));
        }

        private static void initFx(JFXPanel fxPanel) {
          WebView webView = new WebView();
          fxPanel.setScene(new Scene(webView));
          webView.getEngine().load("https://bugreport.java.com/bugreport/");
        }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              pnarayanaswa Praveen Narayanaswamy
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: