我正在尝试调整按钮的大小,但是它不起作用。
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();
}
.button {
-fx-width: 250px;
-fx-background-color: red;
}
我也不能为vbox设置间距。(它可以正常工作)
答案 0 :(得分:2)
尝试以下操作来设置所有按钮的宽度:
.button {
-fx-min-width: 20px;
-fx-max-width: 20px;
-fx-pref-width: 20px;
}
选择要设置的属性( max , min , pref 或全部)。
height 相同,只需将 width 替换为 height 。
要根据this Oracle post设置VBox的间距,您可以使用:
.vbox {
-fx-spacing: 10;
}