title: Java JPanel Resizing to Dimension(10, 10)
body: <p>I am creating a game, and I have a JPanel inside my JFrame, and I want my panel to maintain a constant size ratio: 1.3x1 (as large as possible). I have a component listener on the frame, and when the frame is resized it resets the size of the panel using <code>setPreferredSize</code>, the problem is that every time I change the frame size, the panel gets resized to a <code>Dimension(10, 10)</code> - meaning that the frame is always tiny. The frame also has a <code>GridBagLayout</code> set because i want the panel in the middle. In addition - sometimes if you resize the frame quickly (draw the corner fast) the frame will appear at the right size for a split second, then go back to <code>10, 10</code>.</p>
  
  <p>Resizing code in the component listener:</p>
  
  <pre><code>Game.frameSize.x = (int) Math.round((GameFrame.frameSize.y - 2) * 1.2);
  Game.frameSize.y = GameFrame.frameSize.y - 2;
  this.panel.setPreferredSize(new Dimension(Game.frameSize.x, Game.frameSize.y));
  </code></pre>
  
  <p>* <em>Game is my jpanel and GameFrame is my JFrame, Game.frameSize and GameFrame.frameSize is only for resizing sprites on the screen</em></p>
  
  <p>Configuration of the JFrame and the JPanel</p>
  
  <pre><code>JFrame frame = new JFrame("");
  frame.setLayout(new GridBagLayout());
  frame.setPreferredSize(new Dimension(frameSize.x, frameSize.y));
  frame.setSize(new Dimension(frameSize.x, frameSize.y));
  frame.setMinimumSize(new Dimension(800, 600));
  frame.setResizable(true);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setFocusable(true);
  Game game = new Game(frame);
  Game.frameSize = new Vector((int) Math.round((GameFrame.frameSize.x - 2) * 1.3), GameFrame.frameSize.y - 2);
  game.setSize(new Dimension(frameSize.x, frameSize.y));
  game.setPreferredSize(new Dimension(frameSize.x, frameSize.y));
  frame.addMouseMotionListener(new GameMouseMotionListener());
  frame.addComponentListener(new GameComponentListener(frame, game));
  frame.addMouseListener(new GameMouseListener());
  frame.addKeyListener(new GameKeyListener());
  frame.add(game);
  </code></pre>
  
  <p>I am really not sure what to do here, as far as google is concerned, no one has ever had this issue. Thank you, any help is appreciated :)</p>