2

enter image description hereI'm using GridLayout and all my panels have the same size, how can I change their size?

I tried all functions getPreferred/Minimum/MaximumSize which makes that, and nothing. I still want to stay with GridLayout Any suggestions?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
roeygol
  • 4,908
  • 9
  • 51
  • 88

2 Answers2

6

By its very nature, all components held by a GridLayout will have the same size. If you want them to be different sizes,

  1. You can use a different layout, such as a GridBagLayout or MigLayout or
  2. Use the GridLayout to hold same-sized JPanels that act as containers for other components. The inner components of course can be different sizes. For example: a chess board that holds its chess cells in a GridLayout, but that allows each cell to hold a chess piece that has varying sizes.

If this doesn't answer your question, then please clarify your question.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • 2
    @RoeyGolzarpoor This answer still applies. All the cells will be the same size unless you use multiple layers of layout managers and then you can resize the components within the cells – Dando18 Jan 19 '15 at 23:20
1

So I managed to split all the part above to my first JPanel which located to NORTH.
Then, the JPanel with the button I did the same to be located SOUTH.
So the scrolled JLabel in now located in the CENTER which allows him to be flexible.

    JPanel mainPanel1 = new JPanel(new GridLayout(6,1));
    mainPanel1.add(titleLabel);
    mainPanel1.add(participantPanel);
    mainPanel1.add(swimPanel);
    mainPanel1.add(ridePanel);
    mainPanel1.add(runPanel);
    mainPanel1.add(categoriesPanel);

    JPanel mainPanel2 = new JPanel(new GridLayout(1,1));        
    mainPanel2.add(listPanel);

    JPanel mainPanel3 = new JPanel(new GridLayout(1,1));
    mainPanel3.add(buttonsPanel);

    this.getContentPane().add(mainPanel1, BorderLayout.NORTH);
    this.getContentPane().add(mainPanel2, BorderLayout.CENTER);
    this.getContentPane().add(mainPanel3, BorderLayout.SOUTH);
roeygol
  • 4,908
  • 9
  • 51
  • 88