private void setBoardSize(int rows, int cols) {
      PentominosPanel oldPanel = panel;
      oldPanel.terminate();
      panel = new PentominosPanel(rows,cols,false);
      JMenuBar bar = panel.getMenuBar(!runningAsApplet,oldPanel);
      bar.add(makeSizeMenu());
      setJMenuBar(bar);
      setContentPane(panel);
      pack();
      int squareWidth = panel.getWidth() / cols; 
      int squareHeight = panel.getHeight() / rows; 
      Rectangle bounds = getBounds();
      if (squareHeight < squareWidth)
         bounds.width = 4 + cols*squareHeight; // comment at bottom and menu bar can distort squares when packing
      Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
      if (bounds.x + bounds.width + 20 > screensize.width)
         bounds.x = screensize.width - bounds.width - 20;
      if (bounds.y + bounds.height > screensize.height)
         bounds.y = screensize.height - bounds.height;
      setBounds(bounds);
      validate();  // Seems to be necessary on Windows only.
   }