I'm new to JavaFX and I'm trying to dynamically add buttons to a TilePane based off data stored in a database. For each record that gets returned from the database I'll add a new button the TilePane (FXML of button is listed below). Then this button needs to ben changed on the data stored in the database.
I try to lookup a label that's 2 layers down in the button (child of a Vbox that is placed in the button) it returns null.
What am I doing wrong? I tried to do a Lookup from the Vbox, because i tought that it maybe didn't work beacuse it's a child of a child. Unfortunately this didn't help.
try {
while (res.next()){
addActuator(); //adds the button
Button button = (Button) Actuator_Tile_Pane.lookup("#placeholder");
Label label = (Label) button.lookup("#label"); // returns null
button.setId(res.getString("id"));
System.out.println(label);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
<Button fx:id="placeholder" mnemonicParsing="false" prefHeight="150.0" prefWidth="150.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1">
<graphic>
<VBox fx:id="vbox" alignment="CENTER" prefHeight="200.0" prefWidth="100.0" spacing="10.0">
<children>
<Label fx:id="label" text="Label" />
<ImageView fx:id="img" fitHeight="73.0" fitWidth="98.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icon/lightbulb-on-outline.png" />
</image>
<effect>
<ColorAdjust brightness="-0.12" hue="0.29" saturation="1.0" />
</effect>
</ImageView>
<ToggleButton fx:id="toggle" blendMode="SRC_ATOP" mnemonicParsing="false" text="ToggleButton">
<effect>
<ColorAdjust />
</effect>
</ToggleButton>
</children>
</VBox>
</graphic>
<padding>
<Insets left="20.0" right="20.0" />
</padding>
</Button>