title: JFrame resize question
body: <p>So I am trying to create a JFrame that will resize to a width and height based off a certain fixed value.</p>
  
  <p>i.e.
  when you use the mouse to change the size of the JFrame, if the new width or height value is not a multiple of 20 (the fixed size in the below code), it will round the width or height to the nearest 20, then resize the JFrame.</p>
  
  <p>The width appears to work but the height doesn't...</p>
  
  <p>please help</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  @SuppressWarnings("serial")
  public class test extends JFrame {
  
  private static JPanel panel = new JPanel(null);
  private static int SIZE = 20;
  
  public test() {
      panel.setBackground(Color.RED);
      this.add(panel);
  }
  
  public static void main(String[] args) {
      final test frame = new test();
      frame.setSize(600, 400);
      frame.setVisible(true);
      frame.setLocationRelativeTo(null);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      frame.addComponentListener(new ComponentListener() {
          public void componentResized(ComponentEvent e) {
              if ((panel.getWidth() % SIZE != 0) || (panel.getHeight() % SIZE != 0)) {
                  int screenWidth = ((panel.getWidth() + SIZE) / SIZE) * SIZE;
                  int screenHeight = ((panel.getHeight() + SIZE) / SIZE) * SIZE;
                  frame.setSize(screenWidth, screenHeight);
              }
          }
          public void componentHidden(ComponentEvent arg0) {}
          public void componentMoved(ComponentEvent arg0) {}
          public void componentShown(ComponentEvent arg0) {}
      });
  }
  }
  </code></pre>