我可以在FXML中设置BorderPane元素的宽度吗?
问题描述:
看来我不能在<left>
StackPane上设置任何属性。例如,我想将它的宽度设置为200。我可以在FXML中设置BorderPane元素的宽度吗?
<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);
但对于我的项目的目的,我根本无法做到这一点的方式。有替代品吗?
答
您可以直接翻译您直接发布到FXML Java代码:
<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>
+0
是的,它的工作原理好得多!左窗格现在具有我想要的固定宽度。 – santafebound
我不认为你可以申请'prefWidth'的''标签。你应该在你的''标签内创建一个'StackPane',并在该StackPane上应用prefWidth –