简体   繁体   English

在子元素上设置VBox.vgrow <fx:root> 在JavaFX 8中

[英]Setting VBox.vgrow on a child element of <fx:root> in JavaFX 8

I have the following .fxml file: 我有以下.fxml文件:

<fx:root type="javafx.scene.layout.VBox" xmlns:fx="javafx.com/fxml">
    <Pane VBox.vgrow="ALWAYS">
        <!-- ... -->
    </Pane>
</fx:root>

However, there is an error at VBox.vgrow="ALWAYS" , since <fx:root ... is not exactly a VBox. 但是, VBox.vgrow="ALWAYS"出错,因为<fx:root ...不完全是VBox。 How can I do this in FXML (no Java)? 我怎么能用FXML(没有Java)做到这一点?


Edit: The error in my IDE shows "Attribute VBox.vgrow is not allowed here", and the error the Java application gives is "VBox.vgrow is not a valid attribute." 编辑:我的IDE中的错误显示“此处不允许使用属性VBox.vgrow”,Java应用程序提供的错误是“VBox.vgrow不是有效属性”。

I had neglected to display all my imports of the .fxml file (which only had javafx.scene.layout.Pane ). 我忽略了显示所有导入的.fxml文件(只有javafx.scene.layout.Pane )。

In order for that specific .fxml file to not give an error (see edit), the import javafx.scene.layout.VBox also had to be added, as VBox.* cannot be used on any element unless VBox is imported. 为了使特定的.fxml文件不出错(参见编辑),还必须添加导入javafx.scene.layout.VBox ,因为除非导入VBox否则不能在任何元素上使用VBox.*

The correct .fxml file is: 正确的.fxml文件是:

<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<fx:root type="javafx.scene.layout.VBox" xmlns:fx="javafx.com/fxml">
    <Pane VBox.vgrow="ALWAYS">
        <!-- ... -->
    </Pane>
</fx:root>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM