JOptionPane includes two helper methods to place a JOptionPane within either a modal JDialog or a JInternalFrame and take care of all the previously described behavior:
public JDialog createDialog(Component parentComponent, String title)
public JInternalFrame createInternalFrame(Component parentComponent, String title)