2013-10-11 77 views
0

我創建了兩個Javafx Gridpanes,我希望它們處於同一個ligne中,第二個gridpane必須位於第一個gridpane旁邊的相同ligne中。因爲我在跑步時得到一個。 這是我的代碼:對齊兩個Javafx GridPane

Group root = new Group(); 
    Scene scene = new Scene(root); 

    //creation du layout 
    layout = new GridPane(); 
    layout.getColumnConstraints().add(new ColumnConstraints(350)); // column 1 is 350 wide 
    layout.getColumnConstraints().add(new ColumnConstraints(350)); 
    layout.getColumnConstraints().add(new ColumnConstraints(350)); 
    layout.setGridLinesVisible(true); 

    final Label source = new Label ("DRAG "); 
    layout.add(source, 0, 0); 


    final Label target = new Label ("DROP "); 
    layout.add(target, 1, 0); 

    layout2 = new GridPane(); 
    layout2.getColumnConstraints().add(new ColumnConstraints(20)); // column 1 is 20 wide 

    layout2.setGridLinesVisible(true); 

    final Label source1 = new Label ("fire"); 
    layout2.add(source1, 0, 4); 
    root.getChildren().addAll(layout,layout2); 

回答

2

如果你想下一個將它們添加到對方,最好的選擇是使用HBox佈局:

HBox hBox = new HBox(); 
//hBox.setSpacing(5.0); 
//hBox.setPadding(new Insets(5,5,5,5)); 
hBox.getChildren().addAll(layout, layout2); 
+0

它爲我工作,非常感謝你:) –

+0

@hamza_don不客氣。 –