hamza_tn
hamza_tn

Reputation: 37

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

Upvotes: 0

Views: 3339

Answers (1)

Branislav Lazic
Branislav Lazic

Reputation: 14806

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

Upvotes: 3

Related Questions