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
Here's an example of a panel which:
JPanel panel = JPanel(new GridBagLayout())
panel.setMaximumSize(new Dimension(panel.getMaximumSize().width, panel.getPreferredSize().height))
panel.validate()
panel.repaint()