0
に対する相対座標を取得することはできません
マイコード:JavaFXのは、ノードがシーン
Button btn1 = new Button("Button");
Button btn2 = new Button("The second Button");
VBox vbox = new VBox();
vbox.getChildren().addAll(btn1,btn2);
Scene scene = new Scene(vbox, 300, 300);
System.out.println(btn2.getBoundsInLocal());
System.out.println(btn2.getBoundsInParent());
System.out.println(btn2.getLayoutBounds());
System.out.println(btn2.layoutBoundsProperty());
印刷:
BoundingBox [minX:0.0, minY:0.0, minZ:0.0, width:0.0, height:0.0, depth:0.0, maxX:0.0, maxY:0.0, maxZ:0.0]
BoundingBox [minX:0.0, minY:0.0, minZ:0.0, width:0.0, height:0.0, depth:0.0, maxX:0.0, maxY:0.0, maxZ:0.0]
BoundingBox [minX:0.0, minY:0.0, minZ:0.0, width:0.0, height:0.0, depth:0.0, maxX:0.0, maxY:0.0, maxZ:0.0]
ReadOnlyObjectProperty [bean: [email protected][styleClass=button]'The second Button', name: layoutBounds, value: BoundingBox [minX:0.0, minY:0.0, minZ:0.0, width:0.0, height:0.0, depth:0.0, maxX:0.0, maxY:0.0, maxZ:0.0]]
私の質問です:私はBTN1の座標を取得すると、ミンクスとMINYです0、私は理解することができます。しかし、btn2については、MinYは0であってはならない。 MaxXとMaxYも0であってはいけません。どうすればVBoxのボタンの左隅の実際の座標を取得できますか?明らかにするには、VBoxに関連するノードの座標が必要です。ありがとう。
'primaryStage.show()'の後に 'System.out.println()'ステートメントを移動します。 – Sedrick
レイアウトパス中にサイズと位置が割り当てられますが、これはコードでは発生していません。 – fabian