2014-05-05 29 views
0

我裝使用frame.setUrl(PATH);如何在Java GWT框架中加載元素的中心?

它可以正常工作的HTML,但我想說明它水平居中,有框對象類似於面板部件的.setHorizontalAlignment上沒有方法。

我該如何在GWT frames中居中元素?

我使用Eclipse作爲IDE與GWT Plugin

編輯:我使用com.google.gwt.user.client.ui.Frame;

+0

顯示一些代碼。你在說什麼? – Braj

+0

@Braj我正在使用com.google.gwt.user.client.ui.Frame; –

+0

我已經發布了一個答案。請看一看。 – Braj

回答

2

只需將iframe內的divcenter對齊。

試試這個

public void onModuleLoad() { 

    // Make a new frame, and point it at Google. 
    Frame frame = new Frame("http://www.google.com/"); 

    // Add it to the root panel. 
    RootPanel.get("container").add(frame); 

} 

JSP/HTML:

... 
<body> 
     <div id="container" align="center"></div> 
</body> 
... 

或嘗試這是與上面相同,但div在Java代碼中創建

// Make a new frame, and point it at Google. 
Frame frame = new Frame("http://www.google.com/"); 

DivElement div = Document.get().createDivElement(); 
div.setAttribute("align", "center"); 

div.appendChild(frame.getElement()); 

// Add it to the root panel. 
RootPanel.get().getElement().appendChild(div);