title: Java Set JPanel Height To Percentage Of Window Height
body: <p>I've been trying to set a jpanel's height to 80% of the window's height. Every way I do it creates either a small rectangle, or fills the whole window. Currently, this is my code;</p>
  
  <pre><code>Toolkit tk = Toolkit.getDefaultToolkit();  
  int xSize = ((int) tk.getScreenSize().getWidth());  
  int ySize = ((int) tk.getScreenSize().getHeight());  
  window.setSize(xSize,ySize);
  JPanel p = new JPanel();
  p.setBackground(Color.PINK);
  p.setLayout(new BorderLayout());
  int gameHeight = (int)(Math.round(ySize * 100.0/window.getHeight()));
  int gameWidth = (int)(Math.round(xSize * 100.0/window.getWidth()));
  p.setPreferredSize(new Dimension(gameHeight, gameWidth));
  p.add(new JLabel(" "));
  window.add(p, BorderLayout.SOUTH);
  </code></pre>