0

我已经创建了两个 Javafx Gridpanes,我希望它们在同一个 ligne 中,第二个 gridpane 必须在第一个 gridpane 旁边的同一个 ligne 中。因为我在跑步时会得到一个。这是我的代码:

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

1 回答 1

3

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

HBox hBox = new HBox();
//hBox.setSpacing(5.0); 
//hBox.setPadding(new Insets(5,5,5,5));
hBox.getChildren().addAll(layout, layout2);
于 2013-10-11T14:56:01.227 回答