对齐两个JavaFXGridPane

对齐两个JavaFXGridPane,java,javafx,Java,Javafx,我已经创建了两个Javafx网格窗格,我希望它们处于相同的对齐方式,第二个网格窗格必须位于第一个网格窗格旁边的相同对齐方式。因为我跑步时一个接一个。 这是我的代码: Group root = new Group(); Scene scene = new Scene(root); //creation du layout layout = new GridPane(); layout.getColumnConstraints().add(new ColumnCon

我已经创建了两个Javafx网格窗格,我希望它们处于相同的对齐方式,第二个网格窗格必须位于第一个网格窗格旁边的相同对齐方式。因为我跑步时一个接一个。 这是我的代码:

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);

如果要将它们相邻添加,最好的选择是使用布局:


如果要将它们相邻添加,最好的选择是使用布局:


如果要将它们相邻添加,最好的选择是使用布局:


如果要将它们相邻添加,最好的选择是使用布局:

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