我的按鈕位於矩形下。它目前就像在左邊的圖片中。我想按照右邊的圖片來填充按鈕。
我該怎麼做?謝謝閱讀。
這是我的代碼。
public class Rect extends Application {
private Button btn1 = new Button("Rotate");
private Rectangle r1 = new Rectangle(50, 100);
@Override
public void start(Stage primaryStage) throws Exception {
GridPane gridPane = new GridPane();
r1.setStroke(Color.BLACK);
r1.setFill(Color.WHITE);
gridPane.add(r1, 0, 0);
gridPane.add(btn1, 0, 1);
gridPane.setAlignment(Pos.CENTER);
btn1.setAlignment(Pos.BOTTOM_CENTER);
Scene scene = new Scene(gridPane,200,200);
primaryStage.setTitle("RotateRectangleFX");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
'gridPane.setVgap(...)' –
此時矩形正在向上@James_D – ZpCikTi
如果您調整窗口大小,矩形會再次向下; –