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
By default Container
s have a preferred size that matches the preferred layout size given by the container. So literally all you have to do is:
panel.setSize(panel.getPreferredSize());
Presumably you are doing something odd with the parent to stop the parent's layout manager doing the equivalent of this.