Reputation: 3566
I want to have ImageView which would have label in front of it at centre, but can't figure out which parent layout to use to achieve this.
What I tried so far:
<AnchorPane ...>
<children>
<Pane layoutX="350" layoutY="270" prefHeight="300" prefWidth="300">
<children>
<ImageView fitHeight="300" fitWidth="300">
<image>
<Image url="someimage.png" />
</image>
</ImageView>
</children>
</Pane>
<Pane layoutX="350" layoutY="270" prefHeight="300" prefWidth="300">
<children>
<Label alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" text="num" />
</children>
</Pane>
<more elements/>
</children>
Example what I want (only heart with text):
Upvotes: 0
Views: 1116
Reputation: 34528
Use StackPane
:
StackPane root = new StackPane();
root.getChildren().addAll(
new ImageView("https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/Love_Heart_SVG.svg/200px-Love_Heart_SVG.svg.png"),
new Label("HEART RATE"));
Scene scene = new Scene(root, 300, 250);
Upvotes: 4