Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position JavaFX Button in a specific location

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.

like image 919
Amit Avatar asked Dec 11 '22 22:12

Amit


1 Answers

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);
like image 62
ItachiUchiha Avatar answered Jan 27 '23 20:01

ItachiUchiha