0
我想在一個窗口中製作4個按鈕,如下圖所示對齊。我已經制作了第一個按鈕,即「大按鈕」,但它將居中,我希望它位於左上角,並製作一個易於放置這些按鈕的FX效果程序,如下圖所示:在一個窗口中製作多個按鈕。 Java FX
這是一些編輯的代碼。我快樂了!
包裝樣品;
公共類主要與您使用您添加到該窗格將居中,並在彼此的頂部StackPane一切擴展應用{
@Override
public void start(Stage primaryStage) throws Exception{
//lager top meny stor knapp
HBox topMenu = new HBox();
Button a = new Button("Stor knapp");
a.setPrefSize(120,30);
topMenu.getChildren().addAll(a);
//lager venstre del
HBox left = new HBox();
Button en = new Button("Venstre knapp!");
Button to = new Button("Hoyre knapp!");
left.getChildren().addAll(en,to);
//lager høyre del
VBox right = new VBox();
Button button3 = new Button("Vbox knapp 1!");
Button button4 = new Button("Vbox knapp 2!");
right.getChildren().addAll(button3,button4);
BorderPane borderPane = new BorderPane();
borderPane.setTop(topMenu);
borderPane.setLeft(left);
borderPane.setRight(right);
Scene scene = new Scene(borderPane, 300,300);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
我明白了,但我自己並沒有設法做到這一點。任何人都想用4個按鈕製作這個小窗戶? – petter268
請研究鏈接的資源,並嘗試更難的petter。這是相當基本的佈局設置,對於任何嘗試使用JavaFX創建任何類型的非平凡應用程序的人來說,這都是強制性的。您將通過學習相關文檔和進一步研究構建應用程序,而不是通過爲您提供預構建解決方案的人員學習更多知識。 – jewelsea