javaswinglayoutgrid-layout

Changing width of GridLayout


I use the GridLayout for my JPanel and was wondering, if it's possible to change the width of the columns:

GridLayout grid = new GridLayout(5,2);
panel.setLayout(grid);

Is there a simple way?


Solution

  • You can use separate grid layout for each column.

    GridLayout grid = new GridLayout(1,2); 
        GridLayout grid1 = new GridLayout(5,1);
            GridLayout grid2 = new GridLayout(5,1);
    
    
            grid.add(grid1);
            grid.add(grid2);
    

    You can now set widths of grid1 one and grid2.