JavaFX - setFont()和setStyle()产生明显不同的结果。为什么?

时间:2017-04-28 02:14:02

标签: javafx-8

我注意到如果我使用setFont()设置对象的字体,它总是在屏幕上呈现比使用setStyle()设置相同字体时要小得多。这是为什么?

例如:

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        FlowPane contentPane = new FlowPane();
        contentPane.setPadding(new Insets(10));

        Text setFontText = new Text("setFont(\"Courier\", 14)");
        setFontText.setFont(Font.font("Courier", 14));

        Text setStyleText = new Text("setStyle(\"-fx-font-family:Courier; -fx-font-size: 14pt\")");
        setStyleText.setStyle("-fx-font-family: Courier; -fx-font-size: 14pt");

        contentPane.getChildren().addAll(setFontText, setStyleText);

        primaryStage.setTitle("These Fonts Though");
        primaryStage.setScene(new Scene(contentPane, 500, 275));
        primaryStage.show();
    }

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

这会产生以下显示: output

0 个答案:

没有答案