私はこの問題を数時間苦労しており、以下のサンプルで問題を再現できました。実際のプログラムは、menu
でどのボタンが押されたかに基づいてコンテンツとしてmain.add(node, 0, 1)
に設定されているものを変更します。私はAnchorPanes、setMaxHeightの変更、そして各ペイン内の多くの異なるノードのsetVgrowのようないくつかの異なることを試みましたが、それほど成功しませんでした。この例のリストビューは、ウィンドウの高さの残りの部分を埋めるようにするにはどうすればよいでしょうか?JavaFXノードは、いくつかのペイン内に埋め込まれたときの制約にもかかわらず、高さが増えません。
vgrow
との好適な高さにサイズのものしようとしている
GridPane.setVgrow(content, Priority.ALWAYS);
と
GridPane.setVgrow(subcontent, Priority.ALWAYS);
の両方を必要とする
public class Main extends Application {
public void start(Stage stage) throws Exception {
// I've tried with this as a VBox, no effect.
GridPane main = new GridPane();
main.setGridLinesVisible(true);
main.setHgap(5);
main.setVgap(10);
// Meant to change what content is displayed in the actual program.
HBox menu = new HBox();
menu.setMaxWidth(Double.MAX_VALUE);
menu.setAlignment(Pos.CENTER);
main.add(menu, 0, 0);
GridPane.setHgrow(menu, Priority.ALWAYS);
menu.getChildren().addAll(new Button("Button 1"), new Button("Button 2"), new Button("Button 3"), new Label("Hello world!"));
// Changes often.
GridPane content = new GridPane();
main.add(content, 0, 1);
// Options for the displayed content, changes the StackPane displayed below in my actual program.
HBox submenu = new HBox();
submenu.setMaxWidth(Double.MAX_VALUE);
submenu.setAlignment(Pos.CENTER);
content.add(submenu, 0, 0);
GridPane.setHgrow(submenu, Priority.ALWAYS);
submenu.getChildren().addAll(new Button("Button A"), new Button("Button B"), new Button("Button C"), new Label("Hello world!"));
// This is a custom class extended by StackPane in my actual program. Is often over overlayed with another transparent StackPane (not relevant to the problem).
StackPane subcontent = new StackPane();
subcontent.setMaxHeight(Double.MAX_VALUE);
subcontent.setMaxWidth(Double.MAX_VALUE);
content.add(subcontent, 0, 1);
// This was meant to be a TabPane in my actual program but this has the same outcome that won't fill the rest of the window height.
ListView<String> list = new ListView<>();
list.setMaxHeight(Double.MAX_VALUE);
list.setMaxWidth(Double.MAX_VALUE);
ObservableList<String> items = FXCollections.observableArrayList();
list.setItems(items);
subcontent.getChildren().add(list);
for(int i=0; i<100; i++) {
items.add("# "+i);
}
Scene scene = new Scene(main, 900, 550);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
ありがとう:あなただけのさまざまなノードが自分の推奨サイズを超えて成長できるようにする必要があるとして、最大高さを設定する
は、この例では何もしません!あなたの説明は、何が起こっていたのかを理解するのを助けました。 –