Position JavaFX Button in a specific location
25,314
If you want to specify the exact co-ordinates of your node, you can use a Pane
instead of StackPane.
Your button, if added to a StackPane
or similar layout which supports alignment, must use the translate properties to move the button. You cannot use setLayoutX()
or setLayoutY()
with these layouts.
Try using the following command to move the button from its initial location :
button.setTranslateX(10);
button.setTranslateY(20);
Author by
Amit
Updated on June 05, 2020Comments
-
Amit about 4 years
My Question is how can i position a javafx button in a specific location.
All the time that i tried to do this simple code is resulting that the Button is only located in the Center of the screen and not on my desired location.
(I'm using StackPane)
Code:
Button button = new Button(); button.setLayoutX(x); button.setLayoutY(y);
Thanks in advance ,
Amit.
-
Amit about 9 yearsI'm afraid it is still not working and yes I'm using StackPane and Thanks for replying
-
ItachiUchiha about 9 yearsTranslate will move the node from its current location by the specified value and not place it on the exact X, Y co-ordinate.
-
Amit about 9 yearsSo what do i need to do to make it on the exact X and Y of my desired co-oridnate?
-
James_D about 9 yearsUse a Pane instead of a StackPane
-
ItachiUchiha about 9 yearsUse a Pane, as stated by @James_D