2016-11-26 3 views
0

何らかの理由でtextExampleTwo.setLayoutX(40)が実際にはTextを右に動かすことはありません。これはバグですか、私はここで重要なことを逃しましたか?.setLayoutX()はFlowPaneの位置に影響しません

public void start(Stage stage) throws Exception { 

    FlowPane flowPane = new FlowPane(); 
    flowPane.setOrientation(Orientation.VERTICAL); 

    Text textExampleOne = new Text("An example - 1"); 

    Text textExampleTwo = new Text("An example - 2"); 
    textExampleTwo.setLayoutX(40.0); 

    flowPane.getChildren().addAll(textExampleOne, textExampleTwo); 

    Scene applicationScene = new Scene(flowPane); 
    stage.setHeight(400.0); 
    stage.setWidth(400.0); 
    stage.setScene(applicationScene); 
    stage.show(); 
} 

An image of the application (Note that they are on the same X level)

答えて

1

あなたはここで重要な何かを見逃している:FlowPane含む

多くPaneのは、自分の子どもの位置を決定します。位置決めのために、layoutXおよびlayoutYのプロパティが使用されます。そのうちの1つに新しい値を割り当て、Nodeがそれ自身の子を配置するレイアウトの子である場合、これは次のレイアウトのパス中に戻される位置につながります。

例外はNodeで、managedプロパティはfalseに設定されています。これにより、には、layoutXでもlayoutYも割り当てられません。

あなたの場合、2つの組み合わせが必要なようです。

この場合、マージンを設定することで目的の効果を得ることができます。

// set all insets except the left one to 0 
FlowPane.setMargin(textExampleOne, new Insets(0, 0, 0, 40)); 

注しかしこれは40にx位置を設定していないが、それはNodeの左にサイズ40のスペースを保持していること。このノードの前に十分な子を追加して2番目の列に移動すると、この間隔が列の先頭までの距離を計算するために使用されます。

+0

ああ、助けてくれてありがとう!私が尋ねたいもう一つのことがありますが、ペインのためにこれを行うことはできますか? –

+0

ペインの種類によって異なります... – fabian

関連する問題