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

Blurry rendering of SwingNode with HiDPI scaling in JavaFX

    XMLWordPrintable

Details

    • b13
    • x86_64
    • windows_7

    Description

      A DESCRIPTION OF THE PROBLEM :
      https://stackoverflow.com/q/63444771/59087

      The text rendering on Windows is blurry. When running in a JFrame, not wrapped by a SwingNode, but still part of the same application shown in the video, the quality of the text is flawless. The screen capture shows the application's main window (bottom), which includes the SwingNode along with the aforementioned JFrame (top). You may have to zoom into the straight edge of the letters to see the reason for the blur. It looks to be an half-pixel offset issue, which is strange because there is no blur in other scenarios.

      See the StackOverflow question for more details and screen captures that illustrate the problem, plus additional sample code from other people.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a new project with a dependency on FlyingSaucer (there may be simpler ways to reproduce the issue).
      2. Run the executable test case.
      3. Adjust the scrollbars until the text appears.
      4. Use a third-party tool to zoom into the letters (e.g., Greenshot).


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The text appears crisp.
      ACTUAL -
      The text appears blurry.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.embed.swing.SwingNode;
      import javafx.scene.Scene;
      import javafx.scene.control.SplitPane;
      import javafx.stage.Stage;
      import org.jsoup.Jsoup;
      import org.jsoup.helper.W3CDom;
      import org.xhtmlrenderer.simple.XHTMLPanel;

      import javax.swing.*;

      import static javax.swing.SwingUtilities.invokeLater;
      import static javax.swing.UIManager.getSystemLookAndFeelClassName;
      import static javax.swing.UIManager.setLookAndFeel;

      public class FlyingSourceTest extends Application {
        private final static String HTML = "<!DOCTYPE html><html><head" +
            "><style type='text/css'>body{font-family:serif; background-color: " +
            "#fff; color:#454545;}</style></head><body><p style=\"font-size: " +
            "300px\">TEST</p></body></html>";

        public static void main( String[] args ) {
          Application.launch( args );
        }

        @Override
        public void start( Stage primaryStage ) {
          invokeLater( () -> {
            try {
              setLookAndFeel( getSystemLookAndFeelClassName() );
            } catch( Exception ignored ) {
            }

            primaryStage.setTitle( "Hello World!" );

            final var renderer = new XHTMLPanel();
            renderer.getSharedContext().getTextRenderer().setSmoothingThreshold( 0 );
            renderer.setDocument( new W3CDom().fromJsoup( Jsoup.parse( HTML ) ) );

            final var swingNode = new SwingNode();
            swingNode.setContent( new JScrollPane( renderer ) );

            final var root = new SplitPane( swingNode, swingNode );

            // ----------
            // Here be dragons? Using a StackPane, instead of a SplitPane, works.
            // ----------
            //StackPane root = new StackPane();
            //root.getChildren().add( mSwingNode );

            Platform.runLater( () -> {
              primaryStage.setScene( new Scene( root, 300, 250 ) );
              primaryStage.show();
            } );
          } );
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Could not find one at this time, although investigation is on-going.

      FREQUENCY : always


      Attachments

        1. BlurrySwingNode.java
          2 kB
        2. BlurrySwingNode.png
          BlurrySwingNode.png
          47 kB
        3. BlurrySwingNode2.png
          BlurrySwingNode2.png
          46 kB
        4. FlyingSourceTest.java
          2 kB
        5. fx11label.png
          fx11label.png
          46 kB
        6. fx9label.png
          fx9label.png
          33 kB
        7. label-fix-image.png
          label-fix-image.png
          35 kB
        8. SwingLabel.java
          0.5 kB
        9. SwinLabel.png
          SwinLabel.png
          19 kB

        Issue Links

          Activity

            People

              psadhukhan Prasanta Sadhukhan
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: