I have an Eclipse-RCP project where I need to use JavaFX controls and components within the SWT parts / windows. I include these controls in a simple part that wraps the JavaFX components within an FXCanvas
. However, when I run the application on a computer with a high-DPI screen with font-scaling enabled, the contents of the FXCanvas
render smaller (and blurrier) than those of the SWT part. Also notice that the JavaFX alert (which is on a pure-JavaFX stage and NOT within an FX-Canvas) is even smaller than the contents of the FXCanvas
For comparison, the same application run on a normal-DPI screen and no font-scaling looks as follows:
My code for the FXCanvasPart
is as follows:
public class FXCanvasPart {
private FXCanvas fxCanvas;
private Label label;
private Button jfxButton;
@PostConstruct
public void postConstruct(final Composite parent) {
fxCanvas = new FXCanvas(parent, SWT.NONE);
final BorderPane root = new BorderPane();
label = new Label("This is an FX Label.");
root.setTop(label);
jfxButton = new Button("This is an FX button.");
root.setCenter(jfxButton);
final Scene scene = new Scene(root);
fxCanvas.setScene(scene);
}
}
The SWT-part is equally simple:
public class SWTPart {
private Label label;
private Button button;
@PostConstruct
public void createComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false));
label = new Label(parent, SWT.NULL);
label.setText("This is an SWT text label.");
button = new Button(parent, SWT.NONE);
button.setText("This is an SWT button.");
}
}
The JavaFX dialog is opened through a menu-item of the application using the following handler:
public class OpenDialogHandler {
@Execute
public void execute(Shell shell) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("A JavaFX dialog");
alert.setHeaderText("Header text");
alert.setContentText("This is a JavaFX Alert dialog.");
alert.showAndWait();
}
}
I've uploaded a zip file with the complete Eclipse project demonstrating this problem if that makes it easier to look into this problem.
Would anyone be able to clue me into what's going on and how to resolve this? Thanks!
Both examples were run on using JDK 9.0.4 on Windows 10. Incidentally, when using JDK 8 on a machine with a high-DPI screen, the FXCanvas text is larger but the pure FX Dialog is correctly sized:
This is a known problem: https://bugs.openjdk.java.net/browse/JDK-8191661
The fix is not likely until a couple of releases later.