简体   繁体   中英

Padding button and rectangle

在此处输入图片说明

My button is located under the rectangle. It is currently like in the picture on the left. I want to pad the button like in the picture on the right.
How can I do that? Thanks for reading.
Here's my code.

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);
    }

}

At the moment you are doing this:

gridPane.setAlignment(Pos.CENTER);
btn1.setAlignment(Pos.BOTTOM_CENTER);

You should be setting the alignment of r1 instead like follows:

r1.setAlignment(Pos.CENTER);
btn1.setAlignment(Pos.BOTTOM_CENTER);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM