Код: Выделить всё
/**
* Searches for an appropriate font based on the font family name and size...
*
* @param family The family of the font
* @param size {@literal The point size of the font. This can be a fractional value,
* but must not be negative. If the size is < 0 the default size will be
* used.}
* @return The font that best fits the specified requirements.
*/
public static Font font(String family, double size) {
return font(family, null, null, size);
}
< /code>
Как я понимаю, когда мы используем этот метод, размер должен быть указан в точках (pt
Код: Выделить всё
public class TestFx extends Application {
@Override
public void start(Stage primaryStage) {
var label1 = new Label("Hello, World!");
label1.setFont(Font.font("System", 40));
HBox box1 = new HBox(label1);
box1.setStyle("-fx-background-color: yellow");
var label2 = new Label("Hello, World!");
label2.setStyle("-fx-font-size: 40pt; -fx-font-family: 'System'");
HBox box2 = new HBox(label2);
box2.setStyle("-fx-background-color: red");
var box = new HBox(box1, box2);
VBox root = new VBox(box);
root.setPadding(new Insets(20));
Scene scene = new Scene(root, 600, 150);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Как вы видите, размеры фондов различных. Но, если размер шрифта второй метки установлен в px :
Код: Выделить всё
label2.setStyle("-fx-font-size: 40px; -fx-font-family: 'System'");
Итак, это означает, что единица измерения для Font size in size#font#font
Код: Выделить всё
px
Подробнее здесь: https://stackoverflow.com/questions/796 ... -in-javafx