首页 > 解决方案 > Java FX 为 2 种语言使用 2 种字体

问题描述

我的 Java FX 应用程序包含英语和希伯来语文本,我想将Roboto用于英语文本,将Noto Sans 希伯来语用于希伯来语文本。

我想出的代码不起作用,如下所述,代码:

// java
Parent root = new VBox() {{
    getChildren().addAll(
        new Label("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"),
        new Label("the quick brown fox jumps over the lazy dog"),
        new Label("השפן טעם ביס ואכל קצת גזר חד")
    );
}};
primaryStage.setScene(new Scene(root) {{
    getStylesheets().add(getClass().getResource("style.css").toExternalForm());
}});
primaryStage.show();


// style.css
@font-face {
    src: url('Roboto-Regular.ttf');
}
@font-face {
    src: url('NotoSansHebrew-Regular.ttf');
}
.root {
    /* Attempt 1 - it only takes the first one */
    -fx-font-family: "Roboto" "Noto Sans Hebrew";

    /* Attempt 2 - it only takes the last one */
    -fx-font-family: "Roboto";
    -fx-font-family: "Noto Sans Hebrew";
}

标签: cssjavafxfonts

解决方案


推荐阅读