英文:
Create two buttons next to each other in JavaFX
问题
我想在窗口底部创建两个按钮,一个在最左边,另一个在右边。我正在使用BorderPane和AnchorPane。当运行时,只显示一个按钮,因为我调用了方法BorderPane.setBottom()
两次,第一个调用被执行,第二个调用并没有以我想要的方式执行。是否可以使用BorderPane来实现这一点?我只看到了其他版本的帮助。
BorderPane root = new BorderPane();
AddArea addArea = new AddArea();
DeleteArea deleteArea = new DeleteArea();
root.setLeft(addArea.getPane()); // 使用setLeft来设置左边的按钮
root.setRight(deleteArea.getPane()); // 使用setRight来设置右边的按钮
希望能对你有所帮助!
英文:
I'd like to create two buttons in the bottom of the window, one on the far left and the other one on the right. I'm using BorderPane and AnchorPane. When running only one button is displayed, because I call the method BorderPane.setBottom()
two times, the first call is executed, the second one is not atleast not in a way I'd like it to. Is there a way to do this using BorderPane? I've only seen help for other versions.
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;
}
}
Thank you in advance!
专注分享java语言的经验与见解,让所有开发者获益!
评论