2011-02-28 58 views
1

嗨,我刚开始使用GWT和我得到以下错误,当我在Eclipse中运行项目GWT 2.2 RootPanel CSS错误

19:36:16.084 [错误] [adaptivgwt] 警告: com.google.gwt.user.client.ui.RootPanel 后代将是不正确地定位 ,即不相对于它们 父元素,当 “位置:静态”,这是CSS 默认,在影响。一个可能的 修复程序是调用 'panel.getElement()。getStyle()。setPosition(Position.RELATIVE)'。

java.lang.IllegalStateException: com.google.gwt.user.client.ui.RootPanel 缺少CSS '位置:{相对的,绝对的,固定}' 在com.google.gwt.user。 client.ui.AbsolutePanel.verifyPositionNotStatic(AbsolutePanel.java:279) at com.google.gwt.user.client.ui.AbsolutePanel.add(AbsolutePanel.java:118) at com.ivstel.adaptiv.client.AdaptivGWT。 loadLogin(AdaptivGWT.java:29) 在com.ivstel.adaptiv.client.AdaptivGWT.onModuleLoad(AdaptivGWT.java:21) 在sun.reflect.NativeMethodAccessorImpl.invoke0(母语 方法) 在sun.reflect.NativeMethodAccessorImpl。调用(UNKN自己 源) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知 来源) 在java.lang.reflect.Method.invoke(未知 来源) 在com.google.gwt.dev.shell.ModuleSpace.onLoad( ModuleSpace.java:396) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:183) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510) 在com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352) 在java.lang.Thread.run(未知来源)

这是我的entry point样子:

public class AdaptivGWT implements EntryPoint { 

private static AdaptivGWT singleton; 

     public static AdaptivGWT get() { 
       return singleton; 
     } 

     public void onModuleLoad() { 
       singleton = this; 
       loadLogin(); 
     } 

     public void loadLogin() { 
       RootPanel.get("login").clear(); 
       RootPanel.get("main").clear(); 

       LoginGWT login = new LoginGWT(); 
       RootPanel.get("login").add(login, 10, 10); 
     } 

     public void loadMain(User user) { 
       RootPanel.get("login").clear(); 

       MainGWT main = new MainGWT(); 
       RootPanel.get("main").add(main, 10, 10); 
     } 
} 

HTML文件。

<!doctype html> 
<!-- The DOCTYPE declaration above will set the --> 
<!-- browser's rendering engine into    --> 
<!-- "Standards Mode". Replacing this declaration --> 
<!-- with a "Quirks Mode" doctype may lead to some --> 
<!-- differences in layout.      --> 

<html> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 

    <link type="text/css" rel="stylesheet" href="AdaptivGWT.css"> 

    <title>Adaptiv</title> 

    <script type="text/javascript" language="javascript" src="adaptivgwt/adaptivgwt.nocache.js"></script> 
    </head> 

    <body> 

    <!-- OPTIONAL: include this if you want history support --> 
    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe> 

    <!-- RECOMMENDED if your web app will not function without JavaScript enabled --> 
    <noscript> 
     <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif"> 
     Your web browser must have JavaScript enabled 
     in order for this application to display correctly. 
     </div> 
    </noscript> 

    <div id="login"></div> 
    <div id="main"></div> 

    </body> 
</html> 
+0

我的猜测是这个问题的答案是在这里没有显示的部分:您的主html文件,其中包含'main'和'login'标记的html元素。所以你也可以添加html。 – 2011-02-28 10:41:51

+0

添加了html文件。 – 2011-02-28 12:23:48

回答

3

使用位置参数(即10,10)与add方法需要你想GWT的小部件添加到为子元素,也可以定位元素的元素(即必须有一个属性:position:) 。在你的情况下,div(都带有id main和login)没有位置。改用add(main)代替。如果你想将你的元素放置在左/顶部10像素使用CSS边距或填充(取决于你的用例)。

在附注中,没有必要同时使用'login'和'main'div,您可以简单地使用一个div,或直接将其添加到正文中,即使用get()。这样你就可以完全控制GWT,而不必在html文件中有一部分结构。

+0

非常感谢。删除位置参数修复了它。 – 2011-02-28 14:30:16

+0

我将一些控件直接添加到RootPanel。如何用x/y参数添加组件的根面板?我如何指定我的根面板被定位,还是不可能? – 2012-10-16 14:27:14