Positioning a JavaFX button at a specific location

My question is, how can I put a javafx button in a specific location.

All the time I was trying to do this simple code, the result is the button is only in the center of the screen and not in my desired location.

(I am using StackPane)

code:

Button button = new Button();

button.setLayoutX(x);
button.setLayoutY(y);

      

Thanks in advance,

Amit.

+3


source to share


1 answer


If you want to specify the exact coordinates of your node, you can use Pane

StackPane instead.


Your button, if added in StackPane

or a similar layout that supports alignment, must use translation 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 starting location:

button.setTranslateX(10);
button.setTranslateY(20);

      

+10


source







All Articles