title: Why does painting with Swing behave differently in Java 8 and Java 6?
body: <p>I am working on a Java application using Swing as a GUI. In this project, I was using Java 8 Update 25. I had been writing another graphical application in Java, but I was using Java 6. In both projects, I have written the same paint() method. (Shown below) I was also calling 'repaint()' the same way too. In both projects, I am drawing a string. This string displays the value of a local int, count; Count increases by one each time the paint() method is called.</p>
  
  <p>My question comes when the two projects behave differently. In Java 6, the screen updates super quick and the application behaves as desirable. However, in Java 7 and 8, the application does not display anything. If I increase the delay between repaints, (to about 300 milliseconds) I am able to see the string flicker. However, if I wanted to develop a game in Java 8, the flickering and jittery motion of a character, for example, would be very undesirable.</p>
  
  <p>Why do the different Java versions behave differently in this manner? Is there a way I am able to replicate the smooth repaint (by Java 6) in Java 8 using a similar setup? (as listed below) If there is, how? If not, how would one achieve a smooth, minimal flickering display? (I would prefer this repaint be constantly repainting, but it is not as necessary as the flow of the display)</p>
  
  <p>Thanks for your help in advance,
   ~Rane</p>
  
  <p>Java 6 Project Code:</p>
  
  <pre><code>public class App {
  
  static AppDisplay display = new AppDisplay();
  
    public static void main(String args[]) {
  
      display.setup();
  
      Thread graphics = new Thread() {
        public void run() {
          while(true) {
            display.repaint();
            try {
              Thread.sleep(17); // This is the delay I am talking about above
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
      };
      graphics.start();
  
  
    }
  }
  
  public class AppDisplay() extends JFrame {
    private static final long serialVersionUID = 1L;
  
    int count = 0;
  
    public void setup() {
      this.setSize(600, 600);
      this.setTitle("Application");
      this.setDefaultCloseOperation(EXIT_ON_CLOSE);
      this.setVisible(true);
    }
  
    public void paint(Graphics g) {
      super.paint(g);
      g.drawString("Count: " + count);
      count ++;
    }
  }
  </code></pre>
  
  <p>Java 8 Code:</p>
  
  <pre><code>public class App {
  
  static AppDisplay display = new AppDisplay();
  
    public static void main(String args[]) {
  
      display.setup();
  
      Thread graphics = new Thread() {
        public void run() {
          while(true) {
            display.repaint();
            try {
              Thread.sleep(17); // Delay
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
      };
      graphics.start();
  
  
    }
  }
  
  public class AppDisplay() extends JFrame {
    private static final long serialVersionUID = 1L;
  
    int count = 0;
  
    public void setup() {
      this.setSize(600, 600);
      this.setTitle("Application");
      this.setDefaultCloseOperation(EXIT_ON_CLOSE);
      this.setVisible(true);
    }
  
    public void paint(Graphics g) {
      super.paint(g);
      g.drawString("Count: " + count);
      count ++;
    }
  }
  </code></pre>