Создайте две кнопки рядом друг с другом в JavaFX - PullRequest
0 голосов
/ 04 апреля 2020

Я хотел бы создать две кнопки в нижней части окна, одну слева и другую справа. Я использую BorderPane и AnchorPane. Когда отображается только одна кнопка, потому что я вызываю метод BorderPane.setBottom() два раза, первый вызов выполняется, второй - по крайней мере, не так, как хотелось бы. Есть ли способ сделать это с помощью BorderPane? Я только видел помощь для других версий.

BorderPane root = new BorderPane();
AddArea addArea = new AddArea();
DeleteArea deleteArea = new DeleteArea();
root.setBottom(deleteArea.getPane());
root.setBottom(addArea.getPane());

public class AddArea {
    private final AnchorPane anchorPane = new AnchorPane();
    private final Button addButton = new Button("Add");

    public AddArea() {
        AnchorPane.setBottomAnchor(addButton, 10.0);
        AnchorPane.setLeftAnchor(addButton, 10.0);

        anchorPane.getChildren().addAll(addButton);
    }

    public Node getPane() {
        return anchorPane;
    }
}

public class DeleteArea {
    private final AnchorPane anchorPane = new AnchorPane();
    private final Button deleteButton = new Button("Delete");

    public DeleteArea() {
        AnchorPane.setBottomAnchor(deleteButton, 10.0);
        AnchorPane.setRightAnchor(deleteButton, 10.0);

        anchorPane.getChildren().addAll(deleteButton);
    }
    public Node getPane() {
        return anchorPane;
    }
}

Заранее спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...