GridBagLayout: how to fill all empty spaces

对着背影说爱祢 提交于 2019-12-05 04:04:12

you could set the layout of the container to BorderLayout (or something equivalent) and create an extra JPanel with the GridBagLayout and add it to the container

because of Borderlayout, the JPanel will take as much space as possible

When a GridBagLayout has more space than it needs, it distributes that extra space using the weightx and weighty properties of each cell. If no cells have a non-zero weight property, the extra space is not allocated to any cell, and instead all cells are centered, and sized to their preferred width/height.

If you do c.weighty = 1 for the constraints used by the component containing the JTable, that component will be allocated all extra vertical space. You may also want to do c.weightx = 1 so the table will fill all horizontal space.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!