我正在尝试调整一个按钮大小,但它不起作用。
CSS文件已正确链接到文件。(按钮的颜色更改(
public void start(Stage primaryStage) throws Exception {
VBox root = new VBox();
Button btn = new Button("s");
root.getChildren().addAll(btn);
Scene scene = new Scene(root, 400, 400);
scene.getStylesheets().add("Style.css");
primaryStage.setScene(scene);
primaryStage.show();
}
CSS文件
.button {
-fx-width: 250px;
-fx-background-color: red;
}
也无法为Vbox设置间距。
尝试以设置所有按钮的宽度:
.button {
-fx-min-width: 20px;
-fx-max-width: 20px;
-fx-pref-width: 20px;
}
选择要设置的属性( max , min , pref 或所有这些属性(。
对于 height ,只需将宽度 heigh 。
替换要设置Vbox的间距,根据此Oracle帖子,您可以使用:
.vbox {
-fx-spacing: 10;
}