css - JavaFX 忽略背景和字体粗细

标签 css javafx background

我正在学习基本的 Java 和 JavaFX。我正在尝试将某些样式应用于一个简单的程序。我已成功连接 CSS 和一些样式,其他样式被忽略。因此,我尤其对 -fx-background-color 和 -fx-font-weight 有疑问。 CSS如下:

.label{
-fx-font-size: 16px;
-fx-font-weight: bold;
-fx-font-family: Tarazedi;
-fx-text-fill: #FF9900;    
}

#h1bar {
-fx-text-fill: #000000;
-fx-effect: dropshadow( gaussian, #000000, 1, 0, 1, 1 );
-fx-background-color: linear-gradient( to right,
                             rgba(255, 153, 0, 1) 0px,
                             rgba(255, 153, 0, 1) 16px,
                             rgba(171, 153, 0, 0.67) 32px,
                             rgba(171, 153, 0, 0.67) 480px,
                             rgba(255, 153, 0, 0.33) 720px,
                             rgba(255, 153, 0, 0) 960px
                           );
-fx-padding: 4px;
-fx-background-radius: 16px;
}

Java如下:

    primaryStage.setTitle("Welcome to tarazedi.com!");                      // Define window and title bar.
    GridPane grid = new GridPane();                                         // Create a GridPane

    grid.setHgap(16);                                                       // Set 10px gridlines.
    grid.setVgap(16);
    grid.setPadding(new Insets(32, 32, 32, 32));                            // TRBL padding.

    Label scenetitle = new Label("\uf0a3  Welcome to tarazedi.com!");
    scenetitle.setId("h1bar");
    grid.add(scenetitle, 0, 0, 2, 1);

    Label userName = new Label("User Name:");
    grid.add(userName, 0, 1);

    TextField userTextField = new TextField();
    grid.add(userTextField, 1, 1);

    Label pw = new Label("Password:");
    grid.add(pw, 0, 2);

    PasswordField pwBox = new PasswordField();
    grid.add(pwBox, 1, 2);

    Button btn = new Button("Sign in");
    HBox hbBtn = new HBox(10);
    hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
    hbBtn.getChildren().add(btn);
    grid.add(hbBtn, 1, 4);

    final Text actiontarget = new Text();
    grid.add(actiontarget, 1, 6);

    btn.setOnAction((ActionEvent e) -> {
        actiontarget.setFill(Color.FIREBRICK);
        actiontarget.setText("Sign in button pressed");
    });

    Scene scene = new Scene(grid, 400, 400);                                // Grid is the root node.
    primaryStage.setScene(scene);                                           // Display it.
    scene.getStylesheets().add(VictorSheckelsFX.class.getResource("VictorStyle.css").toExternalForm());
    primaryStage.show();

预期的行为会导致标题栏看起来大致像我网站上的橙色栏:http://victorsheckels.com/ .相反,我的字体上有纯橙色条,没有阴影,也没有粗体。字体大小、系列和颜色以及填充和半径都是 WAI。

最佳答案

使用百分比而不是像素。 JavaFX 不支持报告的非百分比停止 here

例如:

-fx-background-color: linear-gradient(to right,
rgba(255, 153, 0, 1) 0%,
rgba(255, 153, 0, 1) 1.6%,
rgba(171, 153, 0, 0.67) 3.3%,
rgba(171, 153, 0, 0.67) 50%,
rgba(255, 153, 0, 0.33) 75%,
rgba(255, 153, 0, 0) 100%);

关于css - JavaFX 忽略背景和字体粗细,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46571873/

相关文章:

java - 模态窗口之后,父级窗口不再可调整大小

html - 背景顶部的种类(如边框顶部)

css - 列出彼此相邻的元素奇怪地移动了他们的位置

javascript - 背景位置底部 parseInt

java - 在 JavaFX 中将可缩放图形显示为图标的最佳方式?

java - JavaFX 1.8 中的计时器(时钟)

html - 设置为背景时,标题图片不会缩放/拉伸(stretch)到全宽

Android线程在后台

css - SASS中补码和反转的区别?

css - 如何使用 SASS 和 LiveReload 为 CSS 指定正确的输出文件夹?