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

WebView font too small with Swing on high resolution monitor

XMLWordPrintable

    • x86
    • other

      FULL PRODUCT VERSION :
      java version "1.8.0_102"
      Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.15063]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Samsung 4K monitor

      A DESCRIPTION OF THE PROBLEM :
      Run both test files below on Win 10 with 4 K monitor, "SwingWebView.java" and "WebViewSample .java" which load the Google News webpage.

      The font size in "SwingWebView.java" is way too small.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Save each file below, compile and run side by side on Windows 10 with high resolution monitor.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The web page is rendered with the same font size in "SwingWebView.java" and "WebViewSample .java".
      ACTUAL -
      The font size is tiny in "SwingWebView.java". The WebView is rendered in JFXPanel.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /** FIRST FILE */
      import java.awt.Dimension;

      import javax.swing.JFrame;

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

      public class SwingWebView {

      public static void main(String[] args) {

      String url = "https://news.google.ca/";

      JFrame frame = new JFrame();
      frame.setTitle("SwingWebView");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              JFXPanel jfx = new JFXPanel();//implicitly starts JavaFX if not already running
              
              Platform.runLater(() -> {
               final WebView webview = new WebView();
                      jfx.setScene(new Scene(webview));
                      webview.getEngine().load( url );
              });

              frame.getContentPane().add(jfx);

      frame.setPreferredSize(new Dimension(1000, 750));
      frame.pack();
      frame.setVisible(true);
      }
      }

      /** SECOND FILE */
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;
       
      public class WebViewSample extends Application {

      public static final String url = "https://news.google.ca/";

      @Override public void start(Stage stage) {
      WebView webview = new WebView();

              // create the scene
           Scene scene = new Scene(webview);
              stage.setScene(scene);
              stage.show();
              
              // load the web page
      webview.getEngine().load( url );
          }
       
          public static void main(String[] args){
              launch(args);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      webview.setFontScale(1.5);

        1. SwingWebView.java
          0.9 kB
          Priyanka Mangal
        2. SwingWebView.java
          0.9 kB
          Priyanka Mangal
        3. WebViewSample.java
          0.7 kB
          Priyanka Mangal
        4. WebViewSample4K.java
          0.7 kB
          Priyanka Mangal

            azvegint Alexander Zvegintsev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: