【发布时间】:2017-10-04 18:33:38
【问题描述】:
我正在学习基本的 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,内边距和半径也是。
【问题讨论】:
-
如果您使用的是 Java 8,您可能会尝试将 CSS 记录器
com.sun.javafx.Logging.getCSSLogger()设置为显示所有消息。也可以通过日志属性文件来完成。
标签: css javafx background