2012-02-01 113 views
0

显示我有如下代码:如何强制窗口

import org.eclipse.swt.widgets.Display; 

public class ProvaShow { 

    public static void main(String[] args) { 
     try { 
      ProvaShow window = new ProvaShow(); 
      window.open(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public void open() throws InterruptedException { 
     Display display = Display.getDefault(); 
     Shell shell = new Shell(); 
     shell.setSize(450, 300); 
     shell.setText("SWT Application"); 

     Thread.sleep(3000); 

     shell.open(); 
     shell.layout(); 
     shell.forceActive(); 

     while (!shell.isDisposed()) { 
      if (!display.readAndDispatch()) { 
       display.sleep(); 
      } 
     } 
    } 
} 

如果是打开其他应用程序(ES Web浏览器),我怎么能强迫展现给我上运行的Windows?

+0

你想留在上面的窗口其他应用程序?为了让他模态..? – Sorceror 2012-02-01 12:36:50

回答

0

如果你想显示窗口3秒钟,然后将其关闭,然后用

display.timerExec(3000, new Runnable() { 
    @Override 
    public void run() { 
     shell.dispose(); 
    } 
}); 

更换Thread.sleep(3000);,使shell最后...