简体   繁体   中英

Aligning two Javafx GridPane

I have created two Javafx Gridpanes and i want them to be in the same ligne, the second gridpane must be in the same ligne next to the first gridpane. Because i get one on the other when running. This is my code:

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

If you want to add them next to each other, best choice would be to use HBox layout:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM