位置JavaFX的按钮中的特定位置 [英] Position JavaFX Button in a specific location

查看:1617
本文介绍了位置JavaFX的按钮中的特定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是如何在一个特定的位置放置一个JavaFX按钮。

My Question is how can i position a javafx button in a specific location.

所有我试图做这个简单的code中的时间,导致该按钮仅位于屏幕的中心,而不是我想要的位置。

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.

(我使用StackPane)

(I'm using StackPane)

code:

Button button = new Button();

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

由于提前,

阿米特。

推荐答案

如果你想指定节点的精确坐标,你可以使用的 面板 代替的 StackPane

If you want to specify the exact co-ordinates of your node, you can use a Pane instead of StackPane.

您按钮,如果添加到支持对齐 StackPane 或类似的布局,必须使用转换属性来移动的按钮。不能使用 setLayoutX() setLayoutY()这些布局。

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

这篇关于位置JavaFX的按钮中的特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆