私はJavaFXを使い慣れています。私は下のボタンを含むテキストを含むシンプルなメニューを作成しようとしています。JavaFX - StackPaneに複数の要素を追加するにはどうすればいいですか?
私はText title
とButton testButton
の2つの要素を作成しました。それから私はStackPane stackPane
を作成しました。私は次にstackPanes
の子供に2つの要素を追加し、それをnew Scene
に追加しようとしています。ただし、最後の要素のみが表示されます。
StackPaneに複数の要素を追加するにはどうすればよいですか?
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Test Title");
Text title = new Text("hey!");
StackPane.setAlignment(title, Pos.TOP_CENTER);
Button testButton = new Button("Testing");
StackPane.setAlignment(testButton, Pos.TOP_CENTER);
StackPane stackPane = new StackPane();
stackPane.setPrefSize(300, 300);
stackPane.setPadding(new Insets(25, 0, 0, 0));
stackPane.getChildren().add(title);
stackPane.getChildren().add(testButton);
Scene scene = new Scene(stackPane);
primaryStage.setScene(scene);
primaryStage.show();
}
これらは両方ともそこにあり、もう片方の上にスタックされています(これは 'StackPane'が子ノードをレイアウトする方法です)。あなたが望むようにレイアウトしたレイアウトペインを使用してください。 –