Position JavaFX Button in a specific location

烈酒焚心 提交于 2019-12-10 18:08:41

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/30641187/position-javafx-button-in-a-specific-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!