Laying Out Components in a Grid When components are added to the container, they fill the grid left-to-right, top-to-bottom. int rows = 2; int cols = 2; // The next two lines should be in one line. JPanel panel = new JPanel(new GridLayout( rows, cols)); panel.add(component1); panel.add(component2);