openjdk-jfx icon indicating copy to clipboard operation
openjdk-jfx copied to clipboard

JDK-8211294: [windows] TextArea content is blurry with 125% scaling

Open lvxingtu opened this issue 7 years ago • 10 comments
trafficstars

image image

Test Code: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; import javafx.stage.Stage;

public class HelloFX extends Application {

@Override
public void start(Stage stage) {
    String javaVersion = System.getProperty("java.version");
    String javafxVersion = System.getProperty("javafx.version");
    Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
    TextArea ta = new TextArea();
    TextField tf = new TextField();
    VBox root = new VBox();
    root.getChildren().add(ta);
    root.getChildren().add(tf);
    Scene scene = new Scene(root, 640, 480);
    stage.setScene(scene);
    stage.show();
}

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

}

Environment: win 10 scale :125% oracle jdk11

By the way, how can I chang the cursor(I) style and make font rendering better?

lvxingtu avatar Sep 28 '18 07:09 lvxingtu

I can reproduce this on my Win 7 machine with 125% scaling, too.

kevinrushforth avatar Sep 28 '18 23:09 kevinrushforth

Filed in JBS as JDK-8211294. I slightly modified the test case so that the label is rendered and so the TextField and TextArea are initially populated with text.

kevinrushforth avatar Sep 28 '18 23:09 kevinrushforth

I encountered the same Problem on Windows 10 1803 Enterprise and Windows 10 1809 Pro using openjfx 11.0.2 and 12-ea+12.

The blurring is not limited to labels but can also be seen with images and not only happens on 125% but everyhting else than 100% (so 125%, 150%, 175%).

What I also found is that creating a scene with a fixed size of pixels is not the same for different scales, I don't know if this is intended behaviour or part of the same bug? For example with the following you get different results with 100%, 125%, 150%, 175%, where it only actually creates an 1800 by 900 pixel frame on 100% scaling. primaryStage.setScene(new Scene(root, 1800, 900));

This can be fixed by scaling the width and heigth of the scene by Screen.getPrimary().getOutputScaleX() and Screen.getPrimary().getOutputScaleY() respectively. I now ask myself if this scaling has to be done manually for each pixel value of each object in the scene?

Interestingly using Oracle's Java 1.8 I seem to only have scaling issues on 150% and 175% but it works fine on 100% and 125%.

ghost avatar Feb 14 '19 18:02 ghost

Interestingly using Oracle's Java 1.8 I seem to only have scaling issues on 150% and 175% but it works fine on 100% and 125%.

That's because the threshold for using Hi-DPI on JDK 8 is 150% (versus 125% on JDK 9 and later).

kevinrushforth avatar Feb 15 '19 20:02 kevinrushforth

Ah, ok. So is the perceived bluriness and scene scaling a bug or intended beahviour?

ghost avatar Feb 17 '19 10:02 ghost

Workaround for this issue:

Add css:

.text-area > .scroll-pane {
    -fx-skin: "MyScrollPaneSkin"
}

Add java code:

public class MyScrollPaneSkin extends ScrollPaneSkin {
	public MyScrollPaneSkin(final ScrollPane scrollpane) {
		super(scrollpane);
		try {
			Field viewRectField = ScrollPaneSkin.class.getDeclaredField("viewRect");
			viewRectField.setAccessible(true);
			StackPane viewRect = (StackPane) viewRectField.get(this);
			viewRect.setCache(false);
		} catch (Exception e) {
			Logger.getLogger(getClass().getName()).log(Level.SEVERE, "failed to disable scroll pane cache", e);
		}
	}
}

thomas-andres avatar Nov 06 '19 10:11 thomas-andres

@thomas-andres Thank you. It's a great solution. How did you thought the wonderfual soluation?

lvxingtu avatar Nov 07 '19 04:11 lvxingtu

I ran into a similar issue last year, where Font's where blurred inside a scroll pane and found this post: https://stackoverflow.com/questions/26098295/scrollpane-content-becomes-blurry-after-dragging Now I ran into this issue and since the text area also contains a scroll pane I thought it might be the same problem. Happy to see it helps someone else :)

thomas-andres avatar Nov 07 '19 07:11 thomas-andres

Note that this GitHub issue tracker is not actively tracked or managed.

kevinrushforth avatar Dec 02 '19 15:12 kevinrushforth

Workarounds should not be necessary with versions newer than openjfx16 anymore according to https://bugs.openjdk.java.net/browse/JDK-8211294

madmas avatar Feb 23 '21 15:02 madmas