Question

I loaded an html using frame.setUrl(PATH);

It works properly but I want to show it centered horizontally, there are no methods on the frame object that is similar to .setHorizontalAlignment of panel widgets.

How can I center elements in GWT frames?

I am using Eclipse as IDE with GWT Plugin.

EDIT: I am using com.google.gwt.user.client.ui.Frame;

Was it helpful?

Solution

Just enclose the iframe inside a div that is center aligned.

Try this one

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>
...

or try this that is same as above but div is created in JAVA code

// 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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top