在自定义 JavaFX UI 控件中,我想在控件的角落放置一些文本。这是我的 Skin 类的源代码:
double width = control.getWidth();
double height = control.getHeight();
Text test1Text = new Text(0, 0, "top left");
Text test2Text = new Text(0, height-1, "bottom left");
Text test3Text = new Text("top right");
test3Text.relocate(width - test3Text.getLayoutBounds().getWidth(), 0);
Text test4Text = new Text("bottom right");
test4Text.relocate(width - test4Text.getLayoutBounds().getWidth(), height-1);
不幸的是,无论我是在给定坐标处构造文本,还是在没有坐标的情况下构造文本并在之后将其重新定位,这似乎都会有所不同:
- 在第一种情况下,构造函数中的坐标将是文本的左下角坐标。
- 在第二种情况下,给定的坐标将是左上角的坐标。
对于这种奇怪的行为有什么想法吗?