Reputation: 113
i wish to add a grid layout with each row having different cells. As for now i can add or delete only a row or column, i wish to ask if i can add a cell in a particular row or column.
Eg in the below grid image, i wish to ask how i can add a cell in Column 2 . i mean i want to add more cell in column 2 than the rest of column
Upvotes: 1
Views: 2403
Reputation: 18812
You can make each column a 1-column GridPane. Each column can have as many rows as you like. Put all those columns in another 1-row GridPane:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class FxTest extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
GridPane grid = new GridPane();
grid.setPadding(new Insets(5));
for (int i= 0; i< 5 ; i++){
GridPane column = makeColumn(3+i);
grid.add(column, i, 0);
}
Scene scene = new Scene(new Group(grid));
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.show();
}
private GridPane makeColumn(int columns) {
GridPane column = new GridPane();
column.setPadding(new Insets(2));
column.setGridLinesVisible(true);
for(int i = 0; i < columns; i++){
column.add(new Label(" "+i +" "), 0, i);
}
return column;
}
public static void main(String[] args) {
launch(null);
}
}
Upvotes: 0