private void resizePanel(){
  if (parentFrame != null) {
    int additionalParentHeight=(parentFrame.getBounds().height - scroller.getHeight());
    scroller.resize();
    int newHeight=scroller.getPreferredSize().height + additionalParentHeight;
    if (newHeight > 300) {
      parentFrame.pack();
      parentFrame.setLocationRelativeTo(null);
    }
  }
}

private void resizePanel ( ) { if ( parentFrame != null ) { int additionalParentHeight = ( parentFrame . getBounds ( ) . height - scroller . getHeight ( ) ) ; scroller . resize ( ) ; int newHeight = scroller . getPreferredSize ( ) . height + additionalParentHeight ; if ( newHeight > 300 ) { parentFrame . pack ( ) ; parentFrame . setLocationRelativeTo ( null ) ; } } }
resize the panel and parent frame .
