📜  GWT HTMLPanel

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

GWT HTMLPanel

GWT HTMLPanel仅包含HTML内容。我们可以将子窗口小部件添加到html内容中的已标识元素中。

GWT HTMLPanel类声明

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

public class HTMLPanel extends ComplexPanel

GWT HTMLPanel构造函数

Constructor Description
HTMLPanel(SafeHtml safeHtml) It initializes the HTMLPanelanel from the SafeHtml object.
HTMLPanel(java.lang.String html) It creates the HTMLPanel with the specified HTML content inside a DIV element.
HTMLPanel(java.lang.String tag, java.lang.String html) It creates the HTMLPanel whose root element has the given tag. It also has the specified HTML content.

GWT HTMLPanel方法

Modifier and Types Method Description
void add(Widget widget) It adds a child widget to the panel.
void add(Widget widget, Element element) It adds a widget to the panel, contained within a HTML element.
void add(Widget widget, java.lang.String id) It adds a child widget to the panel, contained within the HTML element specified by a given id.
void addAndReplaceElement(IsWidget widget, Element toReplace) It replaces the element. It is the overloaded version for IsWidget.
void addAndReplaceElement(Widget widget, Element toReplace) It adds a child widget to the panel, replacing the HTML element.
void addAndReplaceElement(Widget widget, java.lang.String id) It adds a child widget to the panel, replacing the HTML element specified by a given id.
static java.lang.String createUniqueId() A helper method for creating unique IDs for elements within dynamically- generated HTML.
Element getElementById(java.lang.String id) It finds an element within the panel by its id.
static HTMLPanel removeAllRows() It removes all rows in the table.
void wrap(Element element) It creates a HTML panel that wraps an existing element.

GWT HTMLPanel示例

//SampleHTMLPanel.java


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.RootPanel;

public class HelloWorld implements EntryPoint {
/** * This is the entry point method. */ 
public void onModuleLoad(){ 
// Add buttons to html Panel 
String htmlString = "This HTMLPanel contains" +" html contents ?JavaTpoint.";             
HTMLPanel htmlPanel = new HTMLPanel(htmlString);
 // Add the HTML Panel to the root panel.
 RootPanel.get().add(htmlPanel); 
}

//SampleHTMLPanel.css

body {
   text-align: center;
   font-family: verdana, sans-serif;
}

h1 {
   font-size: 2em;
   font-weight: bold;
   color: #777777;
   margin: 40px 0px 70px;
   text-align: center;
}

输出: