カスタム JavaFX UI コントロールで、コントロールの隅にテキストを配置したいと考えています。私のスキンクラスのソースコードは次のとおりです。
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);
残念ながら、特定の座標でテキストを作成するか、座標なしで作成して後で再配置するかによって、違いが生じるようです。
- 最初のケースでは、コンストラクターの座標はテキストの左下の座標になります。
- 2 番目のケースでは、指定された座標は左上の座標になります。
この奇妙な動作のアイデアはありますか?