JavaFX 8.0有这个bug,不知道怎么解决。
示例:http://i.imgur.com/tavh6XA.png
如果我拖动 ScrollPane,它的内容会变得模糊,但如果我将它拖回来,内容会恢复清晰。如果我不修改坐标,内容看起来还不错。
有人解决过这个问题吗?
示例代码:
@Override
public void start(Stage stage) {
Pane pane = new Pane();
Scene scene = new Scene(pane, 500, 500);
pane.prefWidthProperty().bind(scene.widthProperty());
pane.prefHeightProperty().bind(scene.heightProperty());
ScrollPane scroll = new ScrollPane();
// Center ScrollPane
scroll.layoutXProperty().bind(pane.widthProperty().divide(2).subtract(scroll.widthProperty().divide(2)));
scroll.layoutYProperty().bind(pane.heightProperty().divide(2).subtract(scroll.heightProperty().divide(2)));
scroll.setPrefSize(200, 200);
ListView<String> list = new ListView<>();
scroll.setContent(list);
list.getItems().addAll("Resize the window", "and see how this list", "becomes blurry");
// Label indicates x, y coords of ScrolPane and their ratio.
TextField size = new TextField();
size.setPrefWidth(500);
size.textProperty().bind(
scroll.layoutXProperty()
.asString("x: %s; ").concat(
scroll.layoutYProperty()
.asString("y: %s; ")));
pane.getChildren().addAll(size, scroll);
stage.setScene(scene);
stage.show();
}
最佳答案
我尝试了 thebradness的答案,但我得到一个 java.lang.reflect.InaccessibleObjectException
(Java 10) 可能是因为 Java Platform Module System .与其寻找使反射起作用的变通方法,我更愿意寻找另一种方法来实现它。
检查ScrollPaneSkin
内部代码后,我注意到viewport
css 类被赋予了viewRect
参数。所以我可以通过 CSS 选择器 Node#lookup
而不是通过反射获取它。
这是一个更简单、更易读的解决方案(并且在 JAVA 9+ 中工作):
public void fixBlurryText(ScrollPane scrollPane) {
StackPane stackPane = (StackPane) scrollPane.lookup("ScrollPane .viewport");
stackPane.setCache(false);
}
希望它能帮助到其他人。
关于java - ScrollPane内容拖动后变模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26098295/