title: Java slow 2D performance - Resizing
body: <p>I am using Windows 7 with Aero, and have a very fast graphics card (Radeon 6870) that I use for gaming.</p>
  
  <p>I have some issues when resizing very simple programs I make with java. For instance, this program does absolutely nothing. It has no action listeners, no loops. It's simply a GUI interface with buttons.</p>
  
  <h2>Resizing with OpenGL acceleration off:</h2>
  
  <p><a href="https://i.stack.imgur.com/9y2Xl.png" rel="noreferrer">[View fullscreen]</a>
  <img src="https://i.stack.imgur.com/9y2Xl.png" alt="Sluggish resizing"></p>
  
  <p>It takes about a second to resize the components. For me that's very noticeable.</p>
  
  <h2>Resizing with OpenGL acceleration on:</h2>
  
  <p><img src="https://i.stack.imgur.com/ZGHn3.png" alt="enter image description here"></p>
  
  <p>I have tried to enable OpenGl acceleration to solve this problem. I compiled the JAR and
  run it with <code>java -Dsun.java2d.opengl=true -jar C:\Test.jar</code>. The result is <strong>slightly less</strong> black areas around the window, but much more flickering. In fact the flickering shows up as grey in the screenshot above.</p>
  
  <h2>Is the issue present in any other software?</h2>
  
  <p>No. Eclipse, Netbeans, Chrome and other applications have been tested. None have this issue. Therfore I must conclude that there must be some problem with the code. Various people have run this code and said they have "No issues". If you are going to test it, please make sure you resize the window from the smallest size to the largest size of the screen, whilst moving the mouse in circular motion.</p>
  
  <h2>Code:</h2>
  
  <pre><code>import java.awt.*;
  import javax.swing.*;
  
  public class JFrameWithButtonsTest {
      private int iScreen = 25;  
      private int iLocation = 10;
      JFrame frame = new JFrame();
      Container contentPane = frame.getContentPane();
  
      public JFrameWithButtonsTest() {
          JPanel northButtonPanel = new JPanel();
          northButtonPanel.setLayout(new GridLayout(2,2));
          northButtonPanel.add(new JButton(" I do nothing"));
          northButtonPanel.add(new JButton(" I do nothing"));
          northButtonPanel.add(new JButton(" I do nothing"));
          northButtonPanel.add(new JButton(" I do nothing"));
          contentPane.add(northButtonPanel, BorderLayout.NORTH);
  
          JPanel southButtonPanel = new JPanel();
          southButtonPanel.setLayout(new GridLayout(2,2));
          southButtonPanel.add(new JButton(" I do nothing"));
          southButtonPanel.add(new JButton(" I do nothing"));
          southButtonPanel.add(new JButton(" I do nothing"));
          southButtonPanel.add(new JButton(" I do nothing"));
          contentPane.add(southButtonPanel, BorderLayout.SOUTH);
  
          JPanel eastButtonPanel = new JPanel();
          eastButtonPanel.setLayout(new GridLayout(2,2));
          eastButtonPanel.add(new JButton(" I do nothing"));
          eastButtonPanel.add(new JButton(" I do nothing"));
          eastButtonPanel.add(new JButton(" I do nothing"));
          eastButtonPanel.add(new JButton(" I do nothing"));
          contentPane.add(eastButtonPanel, BorderLayout.EAST);
  
          boolean packFrame = false;
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          Dimension frameSize = frame.getSize();
          frameSize.height = (int) (iScreen * screenSize.height / 100);
          frameSize.width = (int) (iScreen * screenSize.width / 100);
          frame.setSize(frameSize);
          frame.setLocation((screenSize.width - frameSize.width) / iLocation,
                  (screenSize.height - frameSize.height) / iLocation);
          if (packFrame) {
              frame.pack();
              packFrame = true;
          } else {
              frame.validate();
          }
          frame.setVisible(true);
      }
      public static void main(String[] args) {
          try {
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          } catch (Exception e) {
              e.printStackTrace();
          }
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  new JFrameWithButtonsTest();
              }
          });
      }
  }
  </code></pre>
  
  <p>Note that the issue is still present without this line:  <code>UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());</code></p>