set maximum size of JPanel inside BorderLayout.CENTER

前端 未结 3 1612
野趣味
野趣味 2020-12-11 18:08

I have a JPanel inside BorderLayout.CENTER

The JPanel has a Grid Layout, and I want it to expand with the CENTER for its width, but the height must stop at a maximum

3条回答
  •  生来不讨喜
    2020-12-11 18:29

    The FLowLayout layout manager does not redistribute free space; it uses each component's preferred size (see FlowLayout documentation in the Java API).

    I personally would change your wrapper panel's layout manager to a GridBagLayout, and add your centerPanel into it, specify a proper GridBagConstraints object to handle the space distribution as you need.

提交回复
热议问题