2016-10-03 89 views
0

我使用了Java和SWT的Browser。我準備兩個系統版本的應用程序,第一個用於Windows的OSX。不同系統上的SWT

兩個系統都是64位

SWT需要爲不同的系統不同的庫,以便在Maven的,我宣佈雙方

<profile> 
    <id>windows-deploy</id> 

    <dependencies> 
     <dependency> 
      <groupId>org.eclipse.swt</groupId> 
      <artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId> 
      <version>4.6.1</version> 
     </dependency> 
    </dependencies> 
</profile> 

<profile> 
    <id>osx-deploy</id> 

    <dependencies> 
     <dependency> 
      <groupId>org.eclipse.swt</groupId> 
      <artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId> 
      <version>4.6.1</version> 
     </dependency> 
    </dependencies> 
</profile> 

在我加載頁面,然後點擊按鈕(這將創建新的窗口)的瀏覽器,但我做的不想在新窗口打開,只能重裝這新的一頁,我做到了,就像下面的代碼

browser.addOpenWindowListener(new OpenWindowListener() { 
    public void open(WindowEvent event) { 
     Log.debug(TAG + "<>", "Open new page!"); 
     event.browser = browser; 
    } 
}); 

而在OS X系統,它的偉大工程實際的瀏覽器。

但是,當我嘗試在Windows上,點擊按鈕舊頁面後不改變。我檢查了日誌和消息「打開新頁面!」被寫入但沒有任何反應(新頁面不像OS X中加載)。我雖然可以通過WebKit和browser.refresh()刷新瀏覽器刷新加載頁面,但存在舊內容(不像OS X中的新增內容)。

我調試並檢查event.browser = browser; SWT庫中的WebKit控制後發生了什麼。

我應該如何在Windows上獲得像OS X一樣的效果?

+2

請不要過度使用反引號「'」用於關鍵字,它們意味着用於內聯代碼。 – Baz

+0

對不起,我保證我不會以錯誤的方式使用它 – czArek

回答

1

分辨

問題是在庫中。在當我們改變event.browser對象OSX系統,自動檢測和它的工作,但Windows系統上,我們需要添加到瀏覽器VisibilityWindowListener,如下面的代碼片段和做工精細:)

browser.addVisibilityWindowListener(new VisibilityWindowListener() { 
      public void hide(WindowEvent event) { 
      } 

      public void show(WindowEvent event) { 
       Browser browser = (Browser) event.widget; 
       Shell shell = browser.getShell(); 

       if (event.location != null) 
        shell.setLocation(event.location); 

       if (event.size != null) { 
        Point size = event.size; 
        shell.setSize(shell.computeSize(size.x, size.y)); 
       } 

       shell.open(); 
      } 
     }); 
相關問題