title: SWT Dialog does not display correctly
body: <p>When opening a new dialog, while its loading, you click couple of times on parent shell, apparently the new dialog does not display correctly.
  Please see the example below:</p>
  
  <h2>Examples</h2>
  
  <ul>
  <li><a href="https://i.stack.imgur.com/ZovxE.png" rel="nofollow noreferrer">https://i.stack.imgur.com/ZovxE.png</a> (eclipse IDE example)</li>
  <li><a href="https://i.stack.imgur.com/5zVar.png" rel="nofollow noreferrer">https://i.stack.imgur.com/5zVar.png</a></li>
  <li><a href="https://i.stack.imgur.com/u86b9.png" rel="nofollow noreferrer">https://i.stack.imgur.com/u86b9.png</a></li>
  <li><a href="https://i.stack.imgur.com/FGaAr.png" rel="nofollow noreferrer">https://i.stack.imgur.com/FGaAr.png</a></li>
  </ul>
  
  <p>Initially I encountered the problem in december 2014, and back then also reported by vaious in house devlopers which were using different development systems and then same problem has been reported by our several customers.</p>
  
  <p>This behavior can be reproduced using following environment:</p>
  
  <blockquote>
    <ul>
    <li>Windows Version: 7 Pro 64 Bit - 6.1.7601</li>
    <li>Java Version: RE 1.8.0_121_b13</li>
    <li>SWT Versions 
    
    <ul>
    <li>3.8.2</li>
    <li>4.6.2</li>
    <li>4.7M6</li>
    <li>I20170319-2000</li>
    </ul></li>
    </ul>
  </blockquote>
  
  <p>I could only reproduce the problem on Windows 7 with the windows basic theme/design/style (not with classic or aero). 
  On windows 10 its not reproducible. </p>
  
  <h1>reproduce</h1>
  
  <h2>code to reproduce</h2>
  
  <pre><code>package test;
  
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.events.SelectionAdapter;
  import org.eclipse.swt.events.SelectionEvent;
  import org.eclipse.swt.graphics.Rectangle;
  import org.eclipse.swt.layout.GridData;
  import org.eclipse.swt.layout.GridLayout;
  import org.eclipse.swt.layout.RowLayout;
  import org.eclipse.swt.widgets.Button;
  import org.eclipse.swt.widgets.Dialog;
  import org.eclipse.swt.widgets.Display;
  import org.eclipse.swt.widgets.Label;
  import org.eclipse.swt.widgets.Shell;
  import org.eclipse.swt.widgets.Text;
  
  public class Main {
  
      public static void main(String[] args) {
          Display display = new Display();
          final Shell shell = createShell(display);
          createButton(shell);
          shell.open();
          eventLoop(display, shell);
          display.dispose();
      }
  
      private static Shell createShell(Display display) {
          final Shell shell = new Shell(display);
          shell.setLayout(new RowLayout());
          shell.setSize(500, 200);
          return shell;
      }
  
      private static void createButton(final Shell shell) {
          final Button openDialog = new Button(shell, SWT.PUSH);
          openDialog.setText("Click here to open Dialog ...");
          openDialog.addSelectionListener(new SelectionAdapter() {
              public void widgetSelected(SelectionEvent e) {
                  TestDialog inputDialog = new TestDialog(shell);
                  inputDialog.open();
              }
          });
      }
  
      private static void eventLoop(Display display, final Shell shell) {
          while (!shell.isDisposed()) {
              if (!display.readAndDispatch()) {
                  display.sleep();
              }
          }
      }
  }
  
  class TestDialog extends Dialog {
  
      public TestDialog(Shell parent) {
          super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.MIN | SWT.MAX | SWT.RESIZE);
          setText("Dialog");
      }
  
      public void open() {
          Shell shell = new Shell(getParent(), getStyle());
          shell.setText(getText());
          createContents(shell);
          shell.pack();
          initializeBounds(shell);
          shell.open();
          eventLoop(shell);
      }
  
      private void createContents(final Shell shell) {
          shell.setLayout(new GridLayout(2, true));
  
          Label label = new Label(shell, SWT.NONE);
          label.setText("Some Label text ...");
  
          final Text text = new Text(shell, SWT.BORDER);
          GridData data = new GridData(GridData.FILL_HORIZONTAL);
          text.setLayoutData(data);
  
          createCloseButton(shell);
  
          /* time for the user to create the misbehavior */
          try {
              Thread.sleep(15000);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  
      private void createCloseButton(final Shell shell) {
          Button closeButton = new Button(shell, SWT.PUSH);
          closeButton.setText("Close");
          GridData data = new GridData(GridData.FILL_HORIZONTAL);
          closeButton.setLayoutData(data);
          closeButton.addSelectionListener(new SelectionAdapter() {
              public void widgetSelected(SelectionEvent event) {
                  shell.close();
              }
          });
          shell.setDefaultButton(closeButton);
      }
  
      private void initializeBounds(Shell shell) {
          Rectangle bounds = shell.getBounds();
          Rectangle parentBounds = getParent().getBounds();
          bounds.x = parentBounds.x;
          bounds.y = parentBounds.y;
          shell.setBounds(bounds);
      }
  
      private void eventLoop(Shell shell) {
          Display display = getParent().getDisplay();
          while (!shell.isDisposed()) {
              if (!display.readAndDispatch()) {
                  display.sleep();
              }
          }
      }
  }
  </code></pre>
  
  <h2>steps to reproduce</h2>
  
  <ol>
  <li>Start the application
  
  <ul>
  <li>it should look like: <a href="https://i.stack.imgur.com/dMJ9e.png" rel="nofollow noreferrer">https://i.stack.imgur.com/dMJ9e.png</a></li>
  </ul></li>
  <li>Click on the button.</li>
  <li>Keep continuously clicking on right bottom corner of the parent shell (avoid hitting the new opening dialog), till mouse cursor changes to wait icon and parent shell changes its color.
  
  <ul>
  <li>it should look as following: <a href="https://i.stack.imgur.com/c1Ikp.png" rel="nofollow noreferrer">https://i.stack.imgur.com/c1Ikp.png</a></li>
  </ul></li>
  <li>Wait until the new dialog appears.
  
  <ul>
  <li>it looks likes as following: <a href="https://i.stack.imgur.com/kTDgQ.png" rel="nofollow noreferrer">https://i.stack.imgur.com/kTDgQ.png</a> (incorrectly displayed)</li>
  <li>instead: <a href="https://i.stack.imgur.com/cHVjn.png" rel="nofollow noreferrer">https://i.stack.imgur.com/cHVjn.png</a> (correctly displayed)</li>
  </ul></li>
  </ol>
  
  <h3>steps to reproduce done in video</h3>
  
  <ul>
  <li><a href="https://youtu.be/7ukhloCPf0k" rel="nofollow noreferrer">https://youtu.be/7ukhloCPf0k</a></li>
  </ul>
  
  <p>When you mouse hover some of the UI elements (the originally not correctly drawn), you can notice some of them to be get painted (e.g. table rows). </p>
  
  <ol>
  <li><a href="https://i.stack.imgur.com/kkMKn.png" rel="nofollow noreferrer">https://i.stack.imgur.com/kkMKn.png</a> (before opening the dialog)</li>
  <li><a href="https://i.stack.imgur.com/ZXIKc.png" rel="nofollow noreferrer">https://i.stack.imgur.com/ZXIKc.png</a> (after opening the dialog)</li>
  <li><a href="https://i.stack.imgur.com/25M7S.jpg" rel="nofollow noreferrer">https://i.stack.imgur.com/25M7S.jpg</a> (after mouse over)</li>
  </ol>
  
  <p>Even calling <code>Shell.update()</code> or <code>Shell.redraw()</code> after the Dialog opened does not fix it.</p>
  
  <p>In Windows Performance Options -> Visual Effects -> disable "Use visual styles on windows and buttons" is the only option I found which provides a workaround,
  which seems to be the same as changing the design/theme/style to classic. </p>
  
  <ul>
  <li><a href="https://www.sevenforums.com/tutorials/1908-visual-effects-settings-change.html" rel="nofollow noreferrer">https://www.sevenforums.com/tutorials/1908-visual-effects-settings-change.html</a> (How to Change Windows Visual Effects)</li>
  </ul>
  
  <p>In the end, I have following questions:
  Is it a SWT or Windows problem?
  Is there any related topic in bug entries for Windows or in Eclipse Bugzilla?
  Is there someone else who experienced the same problem? please share the experience.
  Is there any settings in SWT or Windows which could affect its look n feel and fix the problem?</p>