@Override public Dimension preferredLayoutSize(Container parent){
  Dimension rd, mbd;
  Insets i=rootPane.getInsets();
  Container contentPane=rootPane.getContentPane();
  JMenuBar menuBar=rootPane.getJMenuBar();
  if (contentPane.isVisible()) {
    rd=contentPane.getPreferredSize();
  }
 else {
    rd=new Dimension(0,contentPane.getPreferredSize().height);
  }
  if (menuBar != null && menuBar.isVisible()) {
    mbd=menuBar.getPreferredSize();
  }
 else {
    mbd=new Dimension(0,0);
  }
  return new Dimension(Math.max(rd.width,mbd.width) + i.left + i.right,rd.height + mbd.height + i.top+ i.bottom);
}

@ Override public Dimension preferredLayoutSize ( Container parent ) { Dimension rd , mbd ; Insets i = rootPane . getInsets ( ) ; Container contentPane = rootPane . getContentPane ( ) ; JMenuBar menuBar = rootPane . getJMenuBar ( ) ; if ( contentPane . isVisible ( ) ) { rd = contentPane . getPreferredSize ( ) ; } else { rd = new Dimension ( 0 , contentPane . getPreferredSize ( ) . height ) ; } if ( menuBar != null && menuBar . isVisible ( ) ) { mbd = menuBar . getPreferredSize ( ) ; } else { mbd = new Dimension ( 0 , 0 ) ; } return new Dimension ( Math . max ( rd . width , mbd . width ) + i . left + i . right , rd . height + mbd . height + i . top + i . bottom ) ; }
returns the amount of space the layout would like to have .
