简体   繁体   中英

JavaFX BorderPane set multiple buttons to Bottom?

Is it possible to have multiple Buttons set to Bottom (left, center, right)?

This is what I tried:

    private Pane createPane() {
        BorderPane rootPane = new BorderPane();
        rootPane.setTop(createMenueBar());
        rootPane.setCenter(createTableView(model.getIssues()));
        
        rootPane.setBottom(createDeleteIssueButton());  
        rootPane.setBottom(createCloseIssueButton());
        rootPane.setBottom(createCreateNewIssueButton());
        
        BorderPane.setAlignment(deleteIssueButton, Pos.BOTTOM_LEFT);
        BorderPane.setAlignment(closeIssueButton, Pos.BOTTOM_CENTER);
        BorderPane.setAlignment(createIssueButton, Pos.BOTTOM_RIGHT);
        return rootPane;
    }

Result:

在此处输入图像描述

As you can see it only shows the last added Button . What is the best way to get this done with JavaFX/BorderPane? I'm very new to this so let me know if you need any more info!

Nested layouts

Gather the multiple buttons into a layout manager . Place that layout manager object in the bottom position of your BorderPane .

For example, you might choose FlowPane as your layout manager.

FlowPane buttons = new FlowPane() ;
buttons.getChildren().addAll( deleteIssueButton , closeIssueButton , createIssueButton ) ;

The BorderPane places only a single widget in the bottom slot. You want your container of buttons to be that widget.

BorderPane rootPane = new BorderPane();
rootPane.setBottom( buttons ) ;

Your use of Pos.BOTTOM_LEFT and such determines where the widget is placed within the bottom slot. The BOTTOM in BOTTOM_LEFT means bottom slot of the given space within a slot, not the bottom of the BorderPane . Two different bottoms involved here.

BorderPane.setAlignment( buttons , Pos.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