JDK-8252255 : Blurry rendering of SwingNode with HiDPI scaling in JavaFX
  • Type: Bug
  • Component: javafx
  • Sub-Component: swing
  • Affected Version: openjfx14
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2020-08-20
  • Updated: 2021-12-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
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



Comments
This doesn't look related to JDK-8211294, nor does it require a SplitPane to reproduce it. A simple JLabel in SwingNode inside any root pane (e.g., a StackPane or VBox) will be blurry when run on a Windows 10 system with 125% HiDPI scaling. A similar FX Label is not blurry. So this is likely a SwingNode bug or a bug in Swing / Java2D. I have attached a simplified program, BlurrySwingNode, which will reproduce this.
29-08-2020

I have attached a test program that was posted to the openjfx-dev list here: https://mail.openjdk.java.net/pipermail/openjfx-dev/2020-August/027368.html To reproduce, run the attached test program on Windows 10 with 125% scaling. See the attached image for results.
24-08-2020

This might be related to JDK-8211294.
24-08-2020