JavaFx大小调整布局

时间:2019-04-03 21:09:04

标签: javafx

我对JavaFx不熟悉,所以我试图在Java Controller类中编写JavaFx组件并在main中调用它们,我的问题是我无法在窗口的所有宽度上调整布局的大小,这个简单的代码:

public Acceuil(){
        LAB_POST = new Button("Posts");
        LAB_EVENT = new Button("Evennements");
        .....
        // my two boxes
        VBox leftPane = new VBox();
        FlowPane bpane = new FlowPane();

        leftPane.setPadding(new Insets(20));
        leftPane.setSpacing(30);
        leftPane.setAlignment(Pos.CENTER);
        leftPane.setStyle("-fx-background-color:#34495e");
        leftPane.setMinWidth(300);
        leftPane.setPrefSize(300, 600);

        bpane.setStyle("-fx-background-color: red;"); // to see the space that it took
        bpane.setMaxWidth(Double.MAX_VALUE);
        bpane.setMaxWidth(Double.MAX_VALUE);
        bpane.setMaxWidth(Double.MAX_VALUE);
        bpane.setMaxWidth(Double.MAX_VALUE);

        leftPane.getChildren().addAll(TXT_SEARCH, LAB_POST....);
        this.getChildren().addAll(leftPane,bpane);


        this.setMinHeight(600);
        this.setMinWidth(900);
}

(注:我尝试了FlowPane,BorderPane,AnchorPane甚至是Boxes) 因此,我希望窗口中剩余的所有空间都含有苯甲醚,但我明白了, interface 所以我想知道我需要输入什么以便让bpane占用所有空间,谢谢

1 个答案:

答案 0 :(得分:2)

我同意Sedrick,我们需要知道这些元素的容器是什么,但是您可以尝试以下方法:

bpane.setStyle("-fx-background-color: red;");
HBox.setHgrow(bpane, Priority.ALWAYS); // Add this line

如果它在AnchorPane中,您也可以尝试以下方法:

AnchorPane.setTopAnchor(this, 0.0);
AnchorPane.setRightAnchor(this, 0.0);
AnchorPane.setBottomAnchor(this, 0.0);
AnchorPane.setLeftAnchor(this, 0.0);
相关问题