[英]setFillWidth doesn't work in JavaFX
I have this code: 我有以下代码:
public class Minesweeper extends Application {
private MenuBar menuBar;
private Stage primaryStage;
private final VBox vbox = new VBox(8);
private GridPane gridpane;
@Override
public void start(Stage primaryStage) {
this.primaryStage=primaryStage;
/*createMenu();
//ImageViewPane viewPane = new ImageViewPane(gridpane);
vbox.getChildren().addAll(menuBar,gridpane);
vbox.setBackground(new Background(fills));*/
HBox hbox = new HBox(50);
hbox.setAlignment(Pos.CENTER); // default TOP_LEFT
VBox vbox1 = new VBox();
//vbox1.setAlignment(Pos.BOTTOM_CENTER);
vbox1.setStyle("-fx-border-style: solid;"
+ "-fx-border-width: 1;"
+ "-fx-border-color: black");
vbox1.setPrefSize(300, 300);
vbox1.setFillWidth(true);
VBox vbox2 = new VBox(10);
vbox2.setAlignment(Pos.CENTER);
vbox2.setStyle("-fx-border-style: solid;"
+ "-fx-border-width: 1;"
+ "-fx-border-color: black");
VBox vbox3 = new VBox(20);
vbox3.setAlignment(Pos.TOP_CENTER);
vbox3.setStyle("-fx-border-style: solid;"
+ "-fx-border-width: 1;"
+ "-fx-border-color: black");
for (int i = 0; i < 5; i++)
{
Button bt = new Button("Button " + (i+1));
Button bt2 = new Button("Button " + (i+1)); // unfortunately there´s no "clone" or "copy" method
Button bt3 = new Button("Button " + (i+1));
vbox1.getChildren().add(bt);
vbox2.getChildren().add(bt2);
vbox3.getChildren().add(bt3);
}
hbox.getChildren().addAll(vbox1, vbox2, vbox3);
Scene scene = new Scene(hbox, 350, 250); // the hbox is the root node
//Scene scene = new Scene(vbox,600,600);
primaryStage.setScene(scene);
primaryStage.setTitle("Minesweeper");
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
and i want the buttons in vbox1 to fill the remaining space (setfillwidth) but it doesn't work. 我希望vbox1中的按钮填充剩余的空间(setfillwidth),但它不起作用。 Maybe iam not using it correctly.
也许我没有正确使用它。
Can someone explain this to me. 谁可以给我解释一下这个。
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.