You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows11下JavaFX 17弹窗字体模糊及宽度不一致问题求助

JavaFX组件自定义开发问题(Windows 11 + Java 17 + JavaFX 17)

在Windows 11搭配Java 17与JavaFX 17环境中进行组件自定义开发时,遇到两个问题:

  • 左侧Popup的字体出现模糊,该问题仅在2K显示器设置125%缩放比例时出现;
  • 右侧的timeSelector宽度与弹窗内的对应组件不一致,未添加额外宽度设置代码,此现象十分奇怪。

最小复现代码

public void start(Stage primaryStage) {
    Scene scene = new Scene(buildFlowPane());
    primaryStage.setScene(scene);
    primaryStage.show();
    Platform.runLater(() -> {
        Popup popup = new Popup();
        popup.getContent().add(buildFlowPane());
        popup.setAnchorX(600);
        popup.show(primaryStage);
    });
}
private FlowPane buildFlowPane(){
    FlowPane flowPane = new FlowPane(){{setStyle("""
                -fx-padding: 2;
                -fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 10, 0, 0, 0);
                -fx-background-radius: 5;
                -fx-background-color: white;
                """);}};
    flowPane.setMinWidth(86);
    flowPane.setMaxWidth(86);
    flowPane.setHgap(1.5);
    flowPane.getChildren().add(buildScrollPane());
    flowPane.getChildren().add(buildScrollPane());
    return flowPane;
}
private ScrollPane buildScrollPane(){
    ScrollPane scrollPane = new ScrollPane(){{setStyle("""
            -fx-padding: 0;
            -fx-background-color: transparent;
            -fx-border-color: transparent;
            -fx-background-insets: 0;
            -fx-hbar-policy: never;
            -fx-vbar-policy: never;
            """);}};
    scrollPane.setMaxHeight(180);
    VBox vBox = new VBox(){{setStyle("-fx-background-color: white;");}};
    ObservableList<Node> children = vBox.getChildren();
    for (int i = 0; i < 24; i++) {
        children.add(buildLabel(String.valueOf(i)));
    }
    scrollPane.setContent(vBox);
    return scrollPane;
}
private Label buildLabel(String text){
    return new Label(text){{setStyle("-fx-pref-width: 38;-fx-pref-height: 29;-fx-alignment: CENTER;-fx-background-radius: 5;-fx-background-color: white");}};
}

问题截图

示例截图:
示例截图

原问题截图:
原问题截图


内容的提问来源于stack exchange,提问作者XiaoJiawei

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 22:20:10