Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have the following .fxml file:

<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. How can I do this in FXML (no 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."

like image 460
TJ Mazeika Avatar asked Oct 29 '25 15:10

TJ Mazeika


1 Answers

I had neglected to display all my imports of the .fxml file (which only had 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.

The correct .fxml file is:

<?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>
like image 145
TJ Mazeika Avatar answered Nov 01 '25 05:11

TJ Mazeika



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!