我想对齐我的按钮,使第一个按钮位于屏幕左侧,另外两个位于右侧。我目前正在使用 HBox 来尝试定位它们,但我似乎无法弄清楚如何正确布置它们。下面的代码是我现在使用的。
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;
public class ButtonTest extends Application {
private Button min, close, openfile;
public static void main(String[] args){
launch(args);
}
@Override
public void start(final Stage stage) throws Exception {
stage.setTitle("Button Test");
Group root = new Group();
BorderPane borderpane = new BorderPane();
setUpButtons();
HBox hbox = new HBox();
hbox.setSpacing(10);
hbox.getChildren().add(openfile);
HBox hbox1 = new HBox();
hbox1.setAlignment(Pos.CENTER_RIGHT);
hbox1.getChildren().addAll(min, close);
hbox.getChildren().add(hbox1);
HBox.setHgrow(hbox1, Priority.ALWAYS);
borderpane.setTop(hbox);
root.getChildren().add(borderpane);
Scene scene = new Scene(root,800,600);
stage.setFullScreen(true);
scene.getStylesheets().add("button.css");
stage.setScene(scene);
stage.show();
}
private void setUpButtons() {
close = new Button("x");
close.setId("closeBtn");
min = new Button("_");
min.setId("minBtn");
openfile = new Button("Open file");
openfile.setId("openFileBtn");
}
}
任何帮助将不胜感激谢谢