title: Using threads to paint panel in java
body: <p>I am writing a program that has a number of different views. One of which is fairly graphics intensive (it displays an interconnected graph). Others just display small but complex diagrams.</p>
  
  <p>I'm finding the paint time for the main view is quite long (even just painting the currently visible area) and while it is being painted, the rest of the interface becomes very slow.</p>
  
  <p>My question is this, can I create a new thread to handle the painting - and if so, will it result in a performance increase, my suspicion is that it wont. I have tried the following:</p>
  
  <p>creating an abstract classs ThreadPaintablePanel, that my complex views inherit from.</p>
  
  <pre><code>public abstract class ThreadPaintablePanel extends JPanel{
   private Thread painter;
   public abstract void paintThread(Graphics g);
  
   protected void callPaintThread(Graphics g){
     if(painter != null){
       painter.interrupt();
     }
     painter = new Thread(new PaintRunnable(this, g));
     painter.start();
   }
  } 
  </code></pre>
  
  <p>Then in my complicated views my <code>paintComponent</code> method is simply: <code>super.callPaintThread(g);</code></p>
  
  <p>The overridden <code>paintThread</code> method contains all my painting code. However this results in unpainted panels. Have I missed something obvious?</p>
  
  <p>Thanks</p>