我可以在 FXML 中设置 BorderPane 元素的宽度吗?

Can I set a BorderPane element's width in FXML?

我似乎无法在 <left> StackPane 上设置任何属性。例如,我想将它的宽度设置为 200。

<BorderPane fx:id="borderPane" fx:controller="main.Controller"
            xmlns:fx="http://javafx.com/fxml" prefHeight="600.0" prefWidth="800.0">

    <left prefWidth="200"> // This doesn't work
        <ListView fx:id="listView"/>
    </left>
    <right>
        <ImageView fx:id="staticImage"/>
    </right>

</BorderPane>

我知道我可以通过编程来做到这一点:

StackPane left = new StackPane();
left.setPrefWidth(200);
borderPane.setLeft(left);

但是为了我的项目的目的,我不能那样做。有其他选择吗?

您可以直接将您发布的 Java 代码翻译成 FXML:

<BorderPane fx:id="borderPane" fx:controller="main.Controller"
            xmlns:fx="http://javafx.com/fxml" prefHeight="600.0" prefWidth="800.0">

    <left>
        <StackPane prefWidth="200" />
    </left>
    <right>
        <ImageView fx:id="staticImage"/>
    </right>

</BorderPane>