Blurry render of SwingNode
Thangalin
thangalin at gmail.com
Sat Aug 22 17:57:27 UTC 2020
Ahoy list,
Running OpenJDK 14.0.1 on Windows 7, adding a SwingNode to a SplitPane
causes the contents of the SwingNode to appear blurry. There's a full
write-up with screen-shots at:
https://stackoverflow.com/q/63444771/59087
Here's an SSCCE that demonstrates the problem:
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javax.swing.*;
import java.awt.*;
import static javafx.application.Platform.runLater;
import static javax.swing.SwingUtilities.invokeLater;
public class FlyingSourceTest extends Application {
public static void main( String[] args ) {
Application.launch( args );
}
@Override
public void start( Stage stage ) {
invokeLater( () -> {
stage.setTitle( "SSCCE" );
final var size = 120f;
final var font = new javafx.scene.text.Font( "Arial", size );
final var bgStyle = "-fx-background-color: white";
// FX label, StackPane
final var fxLabelTop = new javafx.scene.text.Text( "FX/FX" );
fxLabelTop.setFont( font );
final var fxStackPaneTop = new StackPane( fxLabelTop );
// FX label, StackPane
final var fxLabelSplit = new javafx.scene.text.Text( "FX LABEL" );
fxLabelSplit.setFont( font );
final var fxLabelPane = new StackPane();
fxLabelPane.getChildren().addAll( fxLabelSplit );
fxLabelPane.setStyle( bgStyle );
// Swing label, StackPane
final var swingLabel = new JLabel( "SW LABEL" );
swingLabel.setBackground( Color.WHITE );
swingLabel.setOpaque( true );
swingLabel.setFont( swingLabel.getFont().deriveFont( Font.PLAIN, size ) );
final var swingLabelNode = new SwingNode();
swingLabelNode.setContent( swingLabel );
final var swingLabelPane = new StackPane( swingLabelNode );
swingLabelPane.setStyle( bgStyle );
final var fxSplitPane = new SplitPane(
fxLabelPane, swingLabelPane );
fxSplitPane.setPrefSize( 1280, 300 );
final var root = new VBox();
root.getChildren().addAll( fxStackPaneTop, fxSplitPane );
root.setStyle( bgStyle );
runLater( () -> {
final var scene = new Scene( root );
stage.setScene( scene );
stage.show();
} );
} );
}
}
Closely compare the "L" from "SW LABEL" to the "L" from "FX LABEL".
You'll see that the "SW LABEL" ell has what looks like stronger
antialiasing applied.
Changing the Graphics2D rendering hints on the JLabel has no effect.
Changing the JLabel's AffineTransform to shift by 0.5px worsens the
blurriness. Moving the SwingNode out of the SplitPane renders crisply,
as expected. The font colours and background do not affect the
outcome, but are there to make consistent output, which makes
comparing easier.
This problem affects neither X11 (Linux) nor OSX, only Windows.
Been trying to fix this for several days without success.
Any ideas why embedding a SwingNode within a SplitPane causes a blurry
effect? And how can the problem be resolved?
Thank you!
More information about the openjfx-dev
mailing list