public class Tester extends Application {
private static final int WIDTH = 300;
private static final int HEIGHT = 400;
@Override
public void start(Stage stage) {
GridPane pane = new GridPane();
pane.setAlignment(Pos.TOP_LEFT);
pane.setHgap(10);
pane.setVgap(10);
pane.setPadding(new Insets(10, 10, 10, 10));
pane.add(new Button("cat"), 0, 0);
pane.add(new Button("monkey"), 0, 1);
pane.add(new Button("elephant and lion"), 0, 2);
Scene scene = new Scene(pane, WIDTH, HEIGHT);
stage.setScene(scene);
stage.show();
}
}
显示:
如何使所有按钮具有相同的宽度,如下所示:
我试着把按钮加到VBox
上,然后把VBox
加到GridPane
上,但都不行.