📜  GWT RootPanel

📅  最后修改于: 2021-01-02 12:33:10             🧑  作者: Mango

GWT根面板

GWT RootPanel是所有其他Widget所附加的起始面板或最顶层面板。要访问应用程序中的根面板,我们可以使用以下语法: RootPanel.get()。

该面板由html页面组成。根面板返回绑定GWT应用程序的单例值。对于Web应用程序中的控件修改,我们可以如下更改语法: RootPanel.get(String arguments)。

GWT RootPanel类声明

让我们看看com.google.gwt.user.client.ui.RootPanel的声明

public class RootPanel extends AbsolutePanel

GWT RootPanel方法

Modifier and Types Method Description
void clear(boolean clearDom)) It removes all the Dom elements that can cause issues with other elements in page.
static void detachNow(Widget widget) It marks a widget as detached and removes it from the detach list.
static void detachOnWindowClose(Widget widget) It adds a widget to detach list.
static RootPanel get(java.lang.String id) It gets the RootPanel associated with browser element
static Element getBodyElement() It is a simple method for gettin document body element.
static boolean isInDetachList(Widget widget) It determines the given widget is in detach list.

GWT RootPanel示例

//SampleRootPanel.java

import com.google.gwt.event.dom.client.ClickEvent; 
import com.google.gwt.event.dom.client.ClickHandler; 
import com.google.gwt.user.client.ui.FlexTable; 
import com.google.gwt.user.client.ui.Label; 
import com.google.gwt.user.client.ui.RootPanel; 

public void onModuleLoad() {

//This is the entry point method
 public void onModuleLoad() {
 Label lbl = new Label ("JavaTpoint.");
 // Adding label into HTML page. 
     RootPanel.get().add(lbl);
    }
 }

输出: