JPanel size by inner components

前端 未结 8 2201
夕颜
夕颜 2021-02-18 13:48

Is it possible to tell JPanel to set its size to fit all components that it contains? Something like pack() for JFrame.

edit: The trick with preferredSize d

8条回答
  •  盖世英雄少女心
    2021-02-18 14:33

    I had a similar issue using Netbeans GUI Builder. My inner panels were getting weird sizes; I was trying to adjust the minimum and preferred sizes manually, which was a frustrating exercise.

    The problem was solved when I reset all the minimum and preferred sizes back to default (In Netbeans GUI Builder: right click JPanel component -> Properties -> preferredSize -> Reset to Default). When there is no imposed size, the jpanel takes the size of the inner component.

    Note: GridBaLayout was used in my case

提交回复
热议问题