Merge branch 'develop' into trialMerge
[jalview.git] / src / jalview / gui / IdCanvas.java
index 951db78..a9af26d 100755 (executable)
@@ -55,7 +55,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
 
   BufferedImage image;
 
-  Graphics2D gg;
+//  Graphics2D gg;
 
   int imgHeight = 0;
 
@@ -155,7 +155,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     /*
      * for now, not attempting fast paint of wrapped ids...
      */
-    if (gg == null || av.getWrapAlignment())
+    if (image == null || av.getWrapAlignment())
     {
       repaint();
 
@@ -164,6 +164,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
 
     ViewportRanges ranges = av.getRanges();
 
+    Graphics2D gg = image.createGraphics();
     gg.copyArea(0, 0, getWidth(), imgHeight, 0,
             -vertical * av.getCharHeight());
 
@@ -200,6 +201,8 @@ public class IdCanvas extends JPanel implements ViewportListenerI
 
     gg.translate(0, -transY);
 
+    gg.dispose();
+    
     fastPaint = true;
 
     // Call repaint on alignment panel so that repaints from other alignment
@@ -217,7 +220,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
   @Override
   public void paintComponent(Graphics g)
   {
-    super.paintComponent(g);
+    //super.paintComponent(g);  // BH 2019
 
     g.setColor(Color.white);
     g.fillRect(0, 0, getWidth(), getHeight());
@@ -246,13 +249,15 @@ public class IdCanvas extends JPanel implements ViewportListenerI
                 BufferedImage.TYPE_INT_RGB);
     }
     
-    gg = (Graphics2D) image.getGraphics();
+    Graphics2D gg = image.createGraphics();
     
     // Fill in the background
     gg.setColor(Color.white);
     gg.fillRect(0, 0, getWidth(), imgHeight);
     
     drawIds(gg, av, av.getRanges().getStartSeq(), av.getRanges().getEndSeq(), searchResults);
+
+    gg.dispose();
     
     g.drawImage(image, 0, 0, this);
   }