小编Var*_*est的帖子

通过 .css 文件更改 JavaFX 中的字体颜色

有人可以告诉我为什么下面示例中的-fx-text-fill无法更改字体颜色吗?-fx-中风也是我尝试过的。谢谢!

Java文件:

package SimpleTextFromCSS;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class Main extends Application
{
    @Override
    public void start(Stage primaryStage)
    {
        GridPane rootGP = new GridPane();
        Label centerText = new Label("Sample text.");
        rootGP.getChildren().add(centerText);
        Scene scene = new Scene(rootGP,1200,800);
        scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());

        primaryStage.setScene(mainScene);
        primaryStage.show();
        }
    }
    public static void main(String[] args)
    {
        launch(args);
    }
}
Run Code Online (Sandbox Code Playgroud)

CSS:

.root{
  -fx-font-family: "Broadway";
  -fx-font-size: 50pt;
  -fx-text-fill: blue;
}
Run Code Online (Sandbox Code Playgroud)

css javafx

2
推荐指数
1
解决办法
3608
查看次数

标签 统计

css ×1

javafx ×1