I'm building dynamic JDialogs. I have some JPanels, and when you choose a menu option I create a modal JDialog, add a JPanel and display it:
JDialog dlg = new JDialog(this, title, true);
dlg.getContentPane().add(panel);
dlg.pack();
dlg.setLocationRelativeTo(null);
dlg.setVisible(true);
My app is working well, but there is no space between JDialog's border and the added panel, and it looks very "full/stretched" (I'm sorry, I don't know how to say this). Maybe the problem is that I'm calling JDialog.pack(), but at runtime I don't know the size of the panel, so I create the JDialog without dimensions, and after adding the content I pack it.
And my question is: What can I do to add some space around the panel?
One possible solution is adding a BorderLayout, putting the panel at center, and 4 fixed size panels at each side... But this seems an ugly hack...