title: Java Application: drawing a large number of polygons(path2d) taking too long
body: <p>I am trying to write an application that draws a map, using polygon, from arraylist of Path2D.Double coordinates.
  The problem is my sample size is over 26,000 polygons and it takes ages(around 5~6 minutes) to draw the whole thing. Not to mention the fact that it repaints itself when I try to scroll. When the program is run with few thousand coordinates it takes about 5~10 seconds.</p>
  
  <p>is there anyway I can make the program run faster? also is possible to draw it once and use it?, instead of re-drawing the entire map every time I try to scroll or re-size the window.</p>
  
  <p>Thx.</p>
  
  <p>here is the code:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.geom.Path2D;
  import java.awt.geom.Point2D;
  import java.util.ArrayList;
  
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  
  public class WholeMap extends JPanel {
  
      ArrayList&lt;PropertyInfo&gt; propertyList;
      ArrayList&lt;Path2D.Double&gt; polygonList= new ArrayList&lt;Path2D.Double&gt;();
  
      double mapOffsetX = 4200;
      double mapOffsetY = 4000;
  
      public WholeMap(ArrayList&lt;PropertyInfo&gt; pl) {
          propertyList = pl;
          JFrame frame = new JFrame();
          JScrollPane scroll = new JScrollPane(this);
          frame.setVisible(true);
          frame.setBounds(10,10,400,300); //(10, 10, 1100, 900);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setContentPane(scroll);
          initDraw();
      }
  
      public void initDraw() {
          Path2D.Double polygon = new Path2D.Double();
          for (int i = 0; i &lt; propertyList.size(); i++) {
              Point2D[] points = propertyList.get(i).getCoordinate();
              polygon.moveTo(((points[0].getX()-mapOffsetX)/20)+2000,((-points[0].getY()+mapOffsetY)/20)+300);
              for (int j = 1; j &lt; points.length; j++) {
                  polygon.lineTo(((points[j].getX()-mapOffsetX)/20)+2000,((-points[j].getY()+mapOffsetY)/20)+300);
              }
              polygon.closePath();
              polygonList.add(polygon);
          }
      }
  
      @Override
      public Dimension getPreferredSize() {
          return new Dimension(3000, 3000);
      }
  
      public void paintComponent(Graphics g1) {
          super.paintComponent(g1);
          Graphics2D g = (Graphics2D) g1;
          this.setOpaque(true);
          this.setBackground(Color.black);
  
          g.setColor(Color.GRAY);
          for (int k = 0; k &lt; polygonList.size(); k++) {
              g.draw(polygonList.get(k));
              System.out.println("Polygon Count: "+ k);
          }       
      }
  } //EOF
  
  
  
  </code></pre>