Is it possible to tell JPanel to set its size to fit all components that it contains? Something like pack() for JFrame.
pack()
edit: The trick with preferredSize d
maybe you can do something like that by removing from your panel
setResizable(false);