In JavaFX, is there something similar to setLayout();
or setBounds();
?
For example, I want to position a button to a position that I desire.
Everything on JavaFX scene graph is a Node. Each node has a X-coordinate and a Y-coordinate. But there are different ways to set/change position
of a child component. It depends on the layout manager used to show the component on the scene graph.
Group
, which do not compute child's default position and you can use layoutX
and layoutY
directly on themRegion
, which automatically
compute child's default position using layoutX
and inorder to adjust the locations of the components from their default positions you need to use translateX
and translateY
values.From the docs :
If the node is managed and has a Region as its parent, then the layout region will set layoutX according to its own layout policy. If the node is unmanaged or parented by a Group, then the application may set layoutX directly to position it.
You should read up on the Node class (the long text at the beginning), and then especially relocate, setLayoutX (and Y) and setTranslateX (and Y).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With