title: How to change the size of the graphics
body: <p>I have Java applet to draw an array (just some rectangle one after another).</p>
  
  <p>When user select to create array of size <code>n</code>, it will draw <code>n</code> rectangles connected together. When <code>n</code> gets bigger, the graphics get bigger, but since i use <code>JPanel</code> to draw the array, and <code>JPanel</code> won't scroll, i have to add that <code>JPanel</code> into a <code>JScrollPane</code>, but still it won't scroll. The user can see only part of the whole array.</p>
  
  <p>Anyone can give me some help?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class ArrayPanel extends JPanel {
    ....
  
    public void paintComponent(Graphics g) {
      ...draw array here..
      // I wish to get the updated size of the graphis here,
      // then i can reset the preferredSize()....?
      System.out.println("width=" + getWidth() + " height=" + getHeight());
    }
  }
  
  public class ArrayDemo extends JPanel {
    public ArrayDemo() {
   super(new BorderLayout());
  
   arrayPanel = new ArrayPanel();
   arrayPanel.setPreferredSize(new Dimension(400, 300));
  
   JScrollPane container = new JScrollPane(arrayPanel,
           JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
           JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
   container.setPreferredSize(arrayPanel.getPreferredSize());
   add(container, BorderLayout.CENTER);
   ...
    }
  }
  </code></pre>