The largest Interview Solution Library on the web


« Previous | 1 | 2 | 3 | Next »

GWT – LAYOUT PANELS


Layout Panels can contain other widgets. These panels controls the way widgets to be shown on User Interface. Every Panel widget inherits properties from Panel class which in turn inherits properties from Widget class and which in turn inherits properties from UIObject class.
S.N.Widget & Description
1GWT UIObject Class
This widget contains text, not interpreted as HTML using a <div>element, causing it to be displayed with block layout.
2GWT Widget Class
This widget can contain HTML text and displays the html content using a <div> element, causing it to be displayed with block layout.
3GWT Panel Class
This is an is the abstract base class for all panels, which are widgets that can contain other widgets.
GWT - UIObject Class

Introduction

The class UIObject is the superclass for all user-interface objects. It simply wraps a DOM element, and cannot receive events. It provides direct child classes like Widget, MenuItem, MenuItemSeparator, TreeItem.
  • All uiobject objects can be styled using css.
  • Every uiobject has a primary style name that identifies the key css style rule that should always be applied to it.
  • More complex styling behaviour can be achieved by manipulating an object's secondary style name.
Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.UIObject class:

public abstract class UIObject
extends java.lang.Object

Field

Following are the fields for com.google.gwt.user.client.ui.UIObject class:

public static final java.lang.String DEBUG_ID_PREFIX -- The element ID that you specify will be prefixed by the static string DEBUG_ID_PREFIX.

Class Constructors
S.N.Constructor & Description
1UIObject() This creates a UIObject for the child classes.
Class Methods
S.N.Method & Description
1void addStyleDependentName(java.lang.String styleSuffix) Adds a dependent style name by specifying the style name's suffix.
2void addStyleName(java.lang.String style) Adds a secondary or dependent style name to this object.
3static void ensureDebugId(Element elem, java.lang.String id) Ensure that elem has an ID property set, which allows it to integrate with third-party libraries and test tools.
4protected static void ensureDebugId(Element elem, java.lang.String baseID, java.lang.String id) Set the debug id of a specific element.
5ensureDebugId(java.lang.String id) Ensure that the main Element for this UIObject has an ID property set, which allows it to integrate with third-party libraries and test tools.
6int getAbsoluteLeft() Gets the object's absolute left position in pixels, as measured from the browser window's client area.
7int getAbsoluteTop() Gets the object's absolute top position in pixels, as measured from the browser window's client area.
8Element getElement() Gets a handle to the object's underlying DOM element.
9int getOffsetHeight() Gets the object's offset height in pixels.
10int getOffsetWidth() Gets the object's offset width in pixels.
11protected Element getStyleElement() Template method that returns the element to which style names will be applied.
12java.lang.String getStyleName() Gets all of the object's style names, as a space-separated list.
13protected static java.lang.String getStyleName(Element elem) Gets all of the element's style names, as a space-separated list.
14java.lang.String getStylePrimaryName() Gets the primary style name associated with the object.
15protected static java.lang.String getStylePrimaryName(Element elem) Gets the element's primary style name.
16java.lang.String getTitle() Gets the title associated with this object.
17boolean isVisible() Determines whether or not this object is visible.
18static boolean isVisible(Element elem) Determines whether element is visible or not.
19protected void onEnsureDebugId(java.lang.String baseID) Called when the user sets the id using the ensureDebugId(String) method.
20void removeStyleDependentName(java.lang.String styleSuffix) Removes a dependent style name by specifying the style name's suffix.
21void removeStyleName(java.lang.String style) Removes a style name.
22protected void setElement(Element elem) Sets this object's browser element.
23protected void setElement(Element elem) Sets this object's browser element.
24void setHeight(java.lang.String height) Sets the object's height.
25void setPixelSize(int width, int height) Sets the object's size, in pixels, not including decorations such as border, margin, and padding.
26void setSize(java.lang.String width, java.lang.String height) Sets the object's size.
27protected static void setStyleName(Element elem, java.lang.String styleName) Clears all of the element's style names and sets it to the given style.
28protected static void setStyleName(Element elem, java.lang.String style, boolean add) This convenience method adds or removes a style name for a given element.
29void setStyleName(java.lang.String style) Clears all of the object's style names and sets it to the given style.
30protected static void setStylePrimaryName(Element elem, java.lang.String style) Sets the element's primary style name and updates all dependent style names.
31void setStylePrimaryName(java.lang.String style) Sets the object's primary style name and updates all dependent style names.
32void setTitle(java.lang.String title) Sets the title associated with this object.
33void setVisible(boolean visible) Sets whether this object is visible.
34static void setVisible(Element elem, boolean visible) Sets whether this element is visible
35void setWidth(java.lang.String width) Sets the object's width.
36java.lang.String toString() This method is overridden so that any object can be viewed in the debugger as an HTML snippet.
37void unsinkEvents(int eventBitsToRemove) Removes a set of events from this object's event list.
Methods Inherited

This class inherits methods from the following classes:
  • java.lang.Object
GWT - Widget Class

Introduction

The class Widget is the base class for the majority of user-interface objects. Widget adds support for receiving events from the browser and being added directly to panels.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.Widget class:

public class Widget
extends UIObject
implements EventListener

Field

Following are the fields for com.google.gwt.user.client.ui.Widget class:
  • public static final java.lang.String DEBUG_ID_PREFIX -- The element ID that you specify will be prefixed by the static string DEBUG_ID_PREFIX.
Class Constructors
S.N.Constructor & Description
1Widget() This creates a Widget for the child classes.
Class Methods
S.N.Method & Description
1protected <H extends EventHandler> HandlerRegistration addDomHandler(H handler, DomEvent.Type<H> type) Adds a native event handler to the widget and sinks the corresponding native event.
2protected <H extends EventHandler> HandlerRegistration addHandler(H handler, GwtEvent.Type<H> type) Adds this handler to the widget.
3protected void delegateEvent(Widget target, GwtEvent<?> event) Fires an event on a child widget.
4protected void doAttachChildren() If a widget implements HasWidgets, it must override this method and call onAttach() for each of its child widgets.
5protected void doDetachChildren() If a widget implements HasWidgets, it must override this method and call onDetach() for each of its child widgets.
6void fireEvent(GwtEvent<?> event) Fires the given event to all the appropriate handlers.
7protected int getHandlerCount(GwtEvent.Type<?> type) Gets the number of handlers listening to the event type.
8Widget getParent() Gets this widget's parent panel.
9boolean isAttached() Determines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).
10protected boolean isOrWasAttached() Has this widget ever been attached?
11protected void onAttach() This method is called when a widget is attached to the browser's document.
12void onBrowserEvent(Event event) Fired whenever a browser event is received.
13protected void onDetach() This method is called when a widget is detached from the browser's document.
14protected void onLoad() Gets a handle to the object's underlying DOM element.
15protected void onUnload() This method is called immediately before a widget will be detached from the browser's document.
16void removeFromParent() Removes this widget from its parent widget.
17void sinkEvents(int eventBitsToAdd) Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement.
Methods inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
GWT - Panel Class

Introduction

The class Panel is the abstract base class for all panels, which are widgets that can contain other widgets.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.Panel class:

public abstract class Panel
extends Widget
implements HasWidgets.ForIsWidget

Field

Following are the fields for com.google.gwt.user.client.ui.Panel class:
  • public static final java.lang.String DEBUG_ID_PREFIX -- The element ID that you specify will be prefixed by the static string DEBUG_ID_PREFIX.
Class Construc
S.NConstructor & Description
1Panel() This creates a Panel for the child classes.
Class methods
S.N.Method & Description
1void add(IsWidget child)
2void add(Widget child) Adds a child widget.
3protected void adopt(Widget child) Finalize the attachment of a Widget to this Panel.
4protected void adopt(Widget w, Element container) Deprecated. Use adopt(Widget).
5void clear()
6protected void disown(Widget w) Removes all child widgets.
7protected void doAttachChildren() Deprecated. Use orphan(Widget).
8protected void doDetachChildren() If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call Widget.onAttach() for each of its child widgets.
9protected void orphan(Widget child) If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call Widget.onDetach() for each of its child widgets.
10boolean remove(IsWidget child) This method must be called as part of the remove method of any Panel.
11abstract boolean remove(Widget child) Removes a child widget.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
Layout Panels

Following are few important Layout Panels:
S.N.Widget & Description
1FlowPanel
This widget represents a panel that formats its child widgets using the default HTML layout behavior.
2HorizontalPanel
This widget represents a panel that lays all of its widgets out in a single horizontal column.
3VerticalPanel
This widget represents a panel that lays all of its widgets out in a single vertical column.
4HorizontalSplitPanel
This widget represents a panel that arranges two widgets in a single horizontal row and allows the user to interactively change the proportion of the width dedicated to each of the two widgets. Widgets contained within a HorizontalSplitPanel will be automatically decorated with scrollbars when necessary.
5VerticalSplitPanel
This widget represents a A panel that arranges two widgets in a single vertical column and allows the user to interactively change the proportion of the height dedicated to each of the two widgets. Widgets contained within a VertialSplitPanel will be automatically decorated with scrollbars when necessary.
6FlexTable
This widget represents a flexible table that creates cells on demand. It can be jagged (that is, each row can contain a different number of cells) and individual cells can be set to span multiple rows or columns.
7Grid
This widget represents a A rectangular grid that can contain text, html, or a child Widget within its cells. It must be resized explicitly to the desired number of rows and columns.
8DeckPanel
panel that displays all of its child widgets in a 'deck', where only one can be visible at a time. It is used by TabPanel.
9DockPanel
This widget represents a panel that lays its child widgets out "docked" at its outer edges, and allows its last widget to take up the remaining space in its center.
10HTMLPanel
This widget represents a panel that contains HTML, and which can attach child widgets to identified elements within that HTML.
11TabPanel
This widget represents a panel that represents a tabbed set of pages, each of which contains another widget. Its child widgets are shown as the user selects the various tabs associated with them. The tabs can contain arbitrary HTML.
12Composite
This widget represents a type of widget that can wrap another widget, hiding the wrapped widget's methods. When added to a panel, a composite behaves exactly as if the widget it wraps had been added.
13SimplePanel
This widget represents a Base class for panels that contain only one widget.
14ScrollPanel
This widget represents a simple panel that wraps its contents in a scrollable area
15FocusPanel
This widget represents a simple panel that makes its contents focusable, and adds the ability to catch mouse and keyboard events.
16FormPanel
This widget represents a panel that wraps its contents in an HTML <FORM> element.
17PopupPanel
This widget represents a panel that can pop up over other widgets. It overlays the browser's client area (and any previously-created popups).
18DialogBox
This widget represents a form of popup that has a caption area at the
GWT - Flow Panel Widget

Introduction

The FlowPanel widget represents a panel that formats its child widgets using the default HTML layout behavior.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.FlowPanel class:

public class FlowPanel
extends ComplexPanel
implements InsertPanel.ForIsWidget

Class Constructors
S.N.Constructor & Description
1FlowPanel() Constructor for empty Flow Panel.
Class Methods
S.N.Function name & Description
1void add(Widget w) Adds a new child widget to the panel.
2void clear() Removes all child widgets.
3void insert(IsWidget w, int beforeIndex)
4void insert(Widget w, int beforeIndex) Inserts a widget before the specified index.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Panel
  • com.google.gwt.user.client.ui.ComplexPanel
  • java.lang.Object
Flow Panel Widget Example

This example will take you through simple steps to show usage of a FlowPanel Widget in GWT. The following steps will help you update the GWT application which we created in GWT - Create Application chapter:
StepDescription
1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.
Following is the content of the modified module descriptorsrc/com.jtc/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.jtc.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>

Following is the content of the modified Style Sheet file war/HelloWorld.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;
}
.gwt-CheckBox {
margin: 10px;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="HelloWorld.css"/>
<script language="javascript" src="helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>FlowPanel Widget Demonstration</h1>
<div id="gwtContainer"></div>
</body>
</html>

Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of FlowPanel widget.

package com.jtc.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.RootPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// Create a flow panel
FlowPanel flowPanel = new FlowPanel();
// Add CheckBoxes to flow Panel
for(int i = 1; i <= 10; i++){
CheckBox checkBox = new CheckBox("Item" + i);
flowPanel.add(checkBox);
}
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.setWidth("500");
decoratorPanel.add(flowPanel);
// Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel);
}
}

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this this will produce the following result:

GWT - Horizantal Panel Widget

Introduction

The HorizantalPanel widget represents a panel that lays all of its widgets out in a single horizontal column.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.HorizontalPanel class:

public class HorizontalPanel
extends CellPanel
implements HasAlignment, InsertPanel.ForIsWidget

Class Constructors
S.N.Constructor & Description
1HorizontalPanel() Constructor for empty horizontal Panel.
Class methods
S.N.Function name & Description
1void add(Widget w) Adds a child widget.
2HasHorizontalAlignment.HorizontalAlignmentConstant getHorizontalAlignment() Gets the horizontal alignment.
3HasVerticalAlignment.VerticalAlignmentConstant getVerticalAlignment() Gets the vertical alignment.
4void insert(IsWidget w, int beforeIndex)
5void insert(Widget w, int beforeIndex) Inserts a child widget before the specified index.
6protected void onEnsureDebugId(java.lang.String baseID) Affected Elements: -# = the cell at the given index.
7boolean remove(Widget w) Removes a child widget.
8void set Horizontal Alignment(Has Horizontal Ali gnment.Horizontal Alignment Constant align) Sets the default horizontal alignment to be used for widgets added to this panel.
9void setVerticalAlignment(HasVerticalAlignment.VerticalAlignmentConstant align) Sets the default vertical alignment to be used for widgets added to this panel.
Methods inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Panel
  • com.google.gwt.user.client.ui.ComplexPanel
  • com.google.gwt.user.client.ui.CellPanel
  • java.lang.Object
Horizontal Panel Widget Example

This example will take you through simple steps to show usage of a HorizontalPanel Widget in GWT. The following steps will help you to update the GWT application which we created in GWT - Create Application chapter:
StepDescription
1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.
Following is the content of the modified module descriptorsrc/com.jtc/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.jtc.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>

Following is the content of the modified Style Sheet file war/HelloWorld.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;
}
.gwt-CheckBox {
margin: 10px;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="HelloWorld.css"/>
<script language="javascript" src="helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>HorizontalPanel Widget Demonstration</h1>
<div id="gwtContainer"></div>
</body>
</html>

Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of HorizontalPanel widget.

package com.jtc.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// Create a horizontal panel
HorizontalPanel horizontalPanel = new HorizontalPanel();
// Add CheckBoxes to horizontal Panel
for(int i = 1; i <= 10; i++){
CheckBox checkBox = new CheckBox("Item" + i);
horizontalPanel.add(checkBox);
}
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.setWidth("500");
decoratorPanel.add(horizontalPanel);
// Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel); }
}

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

GWT - VerticalPanel Widget

Introduction

The VerticalPanel widget represents a panel that lays all of its widgets out in a single vertical row.

Class Ceclaration

Following is the declaration for com.google.gwt.user.client.ui.VerticalPanel class:

public class VerticalPanel
extends CellPanel
implements HasAlignment, InsertPanel.ForIsWidget

Class Constructors
S.N.Constructor & Description
1VerticalPanel() Constructor for empty vertical Panel.
Class Methods
S.N.Function name & Description
1void add(Widget w) Adds a child widget.
2Has Horizontal Alignment. Horizontal Alignment Constant get Horizontal Alignment() Gets the horizontal alignment.
3HasVerticalAlignment.VerticalAlignmentConstant getVerticalAlignment() Gets the vertical alignment.
4void insert(IsWidget w, int beforeIndex)
5void insert(Widget w, int beforeIndex) Inserts a child widget before the specified index.
6protected void onEnsureDebugId(java.lang.String baseID) Affected Elements: -# = the cell at the given index.
7boolean remove(Widget w) Removes a child widget.
8void set Horizontal Alignment (Has Horizontal Alignment.Horizontal Alignment Constant align) Sets the default horizontal alignment to be used for widgets added to this panel.
9void set Vertical Alignment (Has Vertical Alignment.Vertical Alignment Constant align) Sets the default vertical alignment to be used for widgets added to this panel.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Panel
  • com.google.gwt.user.client.ui.ComplexPanel
  • com.google.gwt.user.client.ui.CellPanel
  • java.lang.Object
VerticalPanel Widget Example

This example will take you through simple steps to show usage of a VerticalPanel Widget in GWT. The following steps will help to you update the GWT application which we created in GWT - Create Application chapter:
StepDescription
1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.
Following is the content of the modified module descriptorsrc/com.jtc/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.jtc.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>

Following is the content of the modified Style Sheet file war/HelloWorld.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;
}
.gwt-CheckBox {
margin: 10px;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="HelloWorld.css"/>
<script language="javascript" src="helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>VerticalPanel Widget Demonstration</h1>
<div id="gwtContainer"></div>
</body>
</html>

Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of VerticalPanel widget.

package com.jtc.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.RootPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// Create a vertical panel
VerticalPanel verticalPanel = new VerticalPanel();
// Add CheckBoxes to vertical Panel
for(int i = 1; i <= 10; i++){
CheckBox checkBox = new CheckBox("Item" + i);
verticalPanel.add(checkBox);
}
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.add(verticalPanel);
// Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel);
}
}

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

GWT - Horizantal Split Panel Widget

Introduction

The Horizantal Split Panel widget represents a panel that arranges two widgets in a single horizontal row and allows the user to interactively change the proportion of the width dedicated to each of the two widgets. Widgets contained within a HorizontalSplitPanel will be automatically decorated with scrollbars when necessary.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.HorizontalSplitPanel class:

@Deprecated
public final class HorizontalSplitPanel
extends Panel

CSS Style Rules

Following default CSS Style rules will be applied to all the HorizontalSpiltPanel widget. You can override it as per your requirements.

.gwt-HorizontalSplitPanel { }
.gwt-HorizontalSplitPanel hsplitter { }

Class Constructors
S.N.Constructor & Description
1HorizontalSplitPanel() Deprecated.
2HorizontalSplitPanel(HorizontalSplitPanel.Resources resources) Deprecated. Creates an empty horizontal split panel.
3HorizontalSplitPanel(HorizontalSplitPanel(HorizontalSplitPanelImages images)) Deprecated. replaced by HorizontalSplitPanel(Resources)
Class Methods
S.N.Function name & Description
1void add(Widget w) Deprecated. Adds a widget to a pane in the HorizontalSplitPanel.
2protected Element getElement(int index) Deprecated. Gets the content element for the given index.
3Widget getEndOfLineWidget() Deprecated. Gets the widget in the pane that is at the end of the line direction for the layout.
4Widget getLeftWidget() Deprecated. Gets the widget in the left side of the panel.
5Widget getRightWidget() Deprecated. Gets the widget in the right side of the panel.
6protected Element getSplitElement() Deprecated. Gets the element that is acting as the splitter.
7Widget getStartOfLineWidget() Deprecated. Gets the widget in the pane that is at the start of the line direction for the layout.
8protected Widget getWidget(int index) Deprecated. Gets one of the contained widgets.
9boolean isResizing() Deprecated. Indicates whether the split panel is being resized.
10java.util.Iterator<Widget> iterator() Deprecated. Gets an iterator for the contained widgets.
11void onBrowserEvent(Event event) Deprecated. Fired whenever a browser event is received.
12protected void onEnsureDebugId(java.lang.String baseID) Deprecated. Affected Elements: -splitter = the container containing the splitter element. -right = the container on the right side of the splitter. -left = the container on the left side of the splitter.
13protected void onLoad() Deprecated. This method is called immediately after a widget becomes attached to the browser's document.
14protected void onUnload() Deprecated. This method is called immediately before a widget will be detached from the browser's document.
15boolean remove(Widget widget) Deprecated. Removes a child widget.
16void setEndOfLineWidget(Widget w) Deprecated. Sets the widget in the pane that is at the end of the line direction for the layout.
17void setLeftWidget(Widget w) Deprecated. Sets the widget in the left side of the panel.
18void setRightWidget(Widget w) Deprecated. Sets the widget in the right side of the panel.
19void setSplitPosition(java.lang.String pos) Deprecated. Moves the position of the splitter.
20void setStartOfLineWidget(Widget w) Deprecated. Sets the widget in the pane that is at the start of the line direction for the layout.
21protected void setWidget(int index, Widget w) Deprecated. Sets one of the contained widgets.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Panel
  • java.lang.Object
Horizontal Split Panel Widget Example

This example will take you through simple steps to show usage of a HorizontalSplitPanel Widget in GWT. The following steps will help to you update the GWT application which we created in GWT - Create Application chapter:
StepDescription
1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.
Following is the content of the modified module descriptorsrc/com.jtc/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.jtc.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>

Following is the content of the modified Style Sheet file war/HelloWorld.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;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="HelloWorld.css"/>
<script language="javascript" src="helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>HorizontalSplitPanel Widget Demonstration</h1>
<div id="gwtContainer"></div>
</body>
</html>

Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of HorizontalSplitPanel widget.

package com.jtc.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// Create a Horizontal Split Panel
HorizontalSplitPanel horizontalSplitPanel = new HorizontalSplitPanel();
horizontalSplitPanel.setSize("300px", "200px");
horizontalSplitPanel.setSplitPosition("30%");
// Add some content
String randomText = "This is a sample text.";
for (int i = 0; i < 2; i++) {
randomText += randomText;
}
horizontalSplitPanel.setRightWidget(new HTML(randomText));
horizontalSplitPanel.setLeftWidget(new HTML(randomText));
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.add(horizontalSplitPanel);
// Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel);
}
}

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

GWT - Vertical Split Panel Widget

Introduction

The Vertical Split Panel widget represents a panel that arranges two widgets in a single vertical column and allows the user to interactively change the proportion of the height dedicated to each of the two widgets. Widgets contained within a VerticalSplitterPanel will be automatically decorated with scrollbars when necessary.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.VerticalSplitPanel class:

@Deprecated
public final class VerticalSplitPanel
extends Panel

CSS Style Rules

Following default CSS Style rules will be applied to all the VerticalSpiltPanel widget. You can override it as per your requirements.

.gwt-VerticalSplitPanel { }
.gwt-VerticalSplitPanel vsplitter { }

Class Constructors
S.N.Constructor & Description
1VerticalSplitPanel() Deprecated.
2VerticalSplitPanel(VerticalSplitPanel.Resources resources) Deprecated. Creates an empty vertical split panel.
3VerticalSplitPanel(VerticalSplitPanelImages images) Deprecated. replaced by VerticalSplitPanel(Resources)
Class Methods
S.N.Function name & Description
1void add(Widget w) Deprecated. Adds a widget to a pane in the HorizontalSplitPanel.
2protected Element getElement(int index) Deprecated. Gets the content element for the given index.
3Widget getEndOfLineWidget() Deprecated. Gets the widget in the pane that is at the end of the line direction for the layout.
4Widget getBottomWidget() Deprecated. Gets the widget in the bottom side of the panel.
5Widget getTopWidget() Deprecated. Gets the widget in the top side of the panel.
6protected Element getSplitElement() Deprecated. Gets the element that is acting as the splitter.
7Widget getStartOfLineWidget() Deprecated. Gets the widget in the pane that is at the start of the line direction for the layout.
8protected Widget getWidget(int index) Deprecated. Gets one of the contained widgets.
9boolean isResizing() Deprecated. Indicates whether the split panel is being resized.
10java.util.Iterator<Widget> iterator() Deprecated. Gets an iterator for the contained widgets.
11void onBrowserEvent(Event event) Deprecated. Fired whenever a browser event is received.
12protected void onEnsureDebugId(java.lang.String baseID) Deprecated. Affected Elements: -splitter = the container containing the splitter element. -right = the container on the right side of the splitter. -left = the container on the left side of the splitter.
13protected void onLoad() Deprecated. This method is called immediately after a widget becomes attached to the browser's document.
14protected void onUnload() Deprecated. This method is called immediately before a widget will be detached from the browser's document.
15boolean remove(Widget widget) Deprecated. Removes a child widget.
16void setEndOfLineWidget(Widget w) Deprecated. Sets the widget in the pane that is at the end of the line direction for the layout.
17void setBottomWidget(Widget w) Deprecated. Sets the widget in the bottom side of the panel.
18void setTopWidget(Widget w) Deprecated. Sets the widget in the top side of the panel.
19void setSplitPosition(java.lang.String pos) Deprecated. Moves the position of the splitter.
20void setStartOfLineWidget(Widget w) Deprecated. Sets the widget in the pane that is at the start of the line direction for the layout.
21protected void setWidget(int index, Widget w) Deprecated. Sets one of the contained widgets.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Panel
  • java.lang.Object
Vertical Split Panel Widget Example

This example will take you through simple steps to show usage of a VerticalSplitPanel Widget in GWT. The following steps will help to you update the GWT application which we created inGWT - Create Application chapter:
StepDescription
1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.
Following is the content of the modified module descriptor src/com.jtc/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.jtc.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>

Following is the content of the modified Style Sheet file war/HelloWorld.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; }

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="HelloWorld.css"/>
<script language="javascript" src="helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>VerticalSplitPanel Widget Demonstration</h1>
<div id="gwtContainer"></div>
</body>
</html>

Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of VerticalSplitPanel widget.

package com.jtc.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalSplitPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// Create a Vertical Split Panel
VerticalSplitPanel verticalSplitPanel = new VerticalSplitPanel();
verticalSplitPanel.setSize("300px", "200px");
verticalSplitPanel.setSplitPosition("35%");
// Add some content
String randomText = "This is a sample text.";
for (int i = 0; i < 2; i++) {
randomText += randomText;
}
verticalSplitPanel.setBottomWidget(new HTML(randomText));
verticalSplitPanel.setTopWidget(new HTML(randomText));
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.add(verticalSplitPanel);
// Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel);
}
}

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this this will produce the following result:

GWT - Flex Table Widget

Introduction

The Flex Table widget represents a flexible table that creates cells on demand. It can be jagged (that is, each row can contain a different number of cells) and individual cells can be set to span multiple rows or columns.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.FlowPanel class:

public class FlexTable
extends HTMLTable

Class Constructors
S.N.Constructor & Description
1FlexTable() Constructor for empty Flex Table.
Class Methods
S.N.Function name & Description
1void addCell(int row) Appends a cell to the specified row.
2int getCellCount(int row) Gets the number of cells on a given row.
3FlexTable.FlexCellFormatter getFlexCellFormatter() Explicitly gets the FlexTable.FlexCellFormatter.
4int getRowCount() Gets the number of rows.
5void insertCell(int beforeRow, int beforeColumn) Inserts a cell into the FlexTable.
6int insertRow(int beforeRow) Inserts a row into the FlexTable.
7protected void prepareCell(int row, int column) Ensure that the cell exists.
8protected void prepareRow(int row) Ensure that the row exists.
9void removeAllRows() Remove all rows in this table.
10void removeCell(int row, int col) Removes the specified cell from the table.
11void removeCells(int row, int column, int num) Removes a number of cells from a row in the table.
12void removeRow(int row) Removes the specified row from the table.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Panel
  • com.google.gwt.user.client.ui.HTMLTable
  • java.lang.Object
Flextable Widget Example

This example will take you through simple steps to show usage of a FlexTable Widget in GWT. The following steps will help to you update the GWT application which we created in GWT - Create Application chapter:
StepDescription
1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.
Following is the content of the modified module descriptor src/com.jtc/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.jtc.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>

Following is the content of the modified Style Sheet file war/HelloWorld.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;
}
.flexTable td {
border: 1px solid #BBBBBB;
padding: 3px;
}
.flexTable-buttonPanel td {
border: 0px;
}
.fixedWidthButton {
width: 150px;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="HelloWorld.css"/>
<script language="javascript" src="helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>FlexTable Widget Demonstration</h1>
<div id="gwtContainer"></div>
</body>
</html>

Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of FlexTable widget.

package com.jtc.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// Create a Flex Table
final FlexTable flexTable = new FlexTable();
FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
flexTable.addStyleName("flexTable");
flexTable.setWidth("32em");
flexTable.setCellSpacing(5);
flexTable.setCellPadding(3);
// Add some text
cellFormatter.setHorizontalAlignment(
0, 1, HasHorizontalAlignment.ALIGN_LEFT);
flexTable.setHTML(0, 0, "This is a FlexTable that supports"
+" <b>colspans</b> and <b>rowspans</b>."
+" You can use it to format your page"
+" or as a special purpose table.");
cellFormatter.setColSpan(0, 0, 2);
// Add a button that will add more rows to the table
Button addRowButton = new Button("Add a Row");
addRowButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
addRow(flexTable);
}
});
addRowButton.addStyleName("fixedWidthButton");
// Add a button that will add more rows to the table
Button removeRowButton = new Button("Remove a Row");
removeRowButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
removeRow(flexTable);
}
});
removeRowButton.addStyleName("fixedWidthButton");
VerticalPanel buttonPanel = new VerticalPanel();
buttonPanel.setStyleName("flexTable-buttonPanel");
buttonPanel.add(addRowButton);
buttonPanel.add(removeRowButton);
flexTable.setWidget(0, 1, buttonPanel);
cellFormatter.setVerticalAlignment(0, 1,
HasVerticalAlignment.ALIGN_TOP);
// Add two rows to start
addRow(flexTable);
addRow(flexTable);
// Add the widgets to the root panel.
RootPanel.get().add(flexTable);
}
/**
* Add a row to the flex table.
*/
private void addRow(FlexTable flexTable) {
int numRows = flexTable.getRowCount();
flexTable.setWidget(numRows, 0,
new Image("http://www.jtc.com/images/gwt-mini.png"));
flexTable.setWidget(numRows, 1,
new Image("http://www.jtc.com/images/gwt-mini.png"));
flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);
}
/**
* Remove a row from the flex table.
*/
private void removeRow(FlexTable flexTable) {
int numRows = flexTable.getRowCount();
if (numRows > 1) {
flexTable.removeRow(numRows - 1);
flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows - 1);
}
}
}

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

GWT - Grid Widget

Introduction

The Grid widget represents a rectangular grid that can contain text, html, or a child Widget within its cells. It must be resized explicitly to the desired number of rows and columns.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.Grid class:

public class Grid
extends HTMLTable

Class constructors
S.N.Constructor & Description
1Grid()
Constructor for Grid.
2Grid(int rows, int columns)
Constructor for Grid with requested size.
Class Methods
S.N.Function name & Description
1boolean clearCell(int row, int column) Replaces the contents of the specified cell with a single space.
2protected Element createCell() Creates a new, empty cell.
3int getCellCount(int row) Return number of columns.
4int getColumnCount() Gets the number of columns in this grid.
5int getRowCount() Return number of rows.
6int insertRow(int beforeRow) Inserts a new row into the table.
7protected void prepareCell(int row, int column) Checks that a cell is a valid cell in the table.
8protected void prepareColumn(int column) Checks that the column index is valid.
9protected void prepareRow(int row) Checks that the row index is valid.
10void removeRow(int row) Removes the specified row from the table.
11void resize(int rows, int columns) Resizes the grid.
12void resizeColumns(int columns) Resizes the grid to the specified number of columns.
13void resizeRows(int rows) Resizes the grid to the specified number of rows.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Panel
  • com.google.gwt.user.client.ui.HTMLTable
  • java.lang.Object
Grid Widget Example

This example will take you through simple steps to show usage of a Grid Widget in GWT. The following steps will help to you update the GWT application which we created in GWT - Create Application chapter:
StepDescription
1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.
Following is the content of the modified module descriptor src/com.jtc/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.jtc.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>

Following is the content of the modified Style Sheet file war/HelloWorld.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;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="HelloWorld.css"/>
<script language="javascript" src="helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>Grid Widget Demonstration</h1>
<div id="gwtContainer"></div>
</body>
</html>

Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of Grid widget.

package com.jtc.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// Create a grid
Grid grid = new Grid(2, 2);
// Add images to the grid
int numRows = grid.getRowCount();
int numColumns = grid.getColumnCount();
for (int row = 0; row < numRows; row++) {
for (int col = 0; col < numColumns; col++) {
grid.setWidget(row, col,
new Image("http://www.jtc.com/images/gwt-mini.png"));
}
}
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.add(grid);
// Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel);
}
}

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

GWT - Deck Panel Widget

Introduction

The DeckPanel widget represents a panel that displays all of its child widgets in a 'deck', where only one can be visible at a time. It is used by TabPanel.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.DeckPanel class:

public class DeckPanel
extends ComplexPanel
implements HasAnimation, InsertPanel.ForIsWidget

Class Constructors
S.N.Constructor & Description
1DeckPanel() Constructor for DeckPanel.
Class Methods
S.N.Function name & Description
1void add(Widget w) Adds a child widget.
2int getVisibleWidget() Gets the index of the currently-visible widget.
3void insert(IsWidget w, int beforeIndex)
4void insert(Widget w, int beforeIndex) Inserts a child widget before the specified index.
5boolean isAnimationEnabled() Returns true if animations are enabled, false if not.
6boolean remove(Widget w) Removes a child widget.
7void setAnimationEnabled(boolean enable) Enable or disable animations.
8void showWidget(int index) Shows the widget at the specified index.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Panel
  • com.google.gwt.user.client.ui.ComplexPanel
  • java.lang.Object
Deckpanel Widget Example

This example will take you through simple steps to show usage of a DeckPanel Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter:
StepDescription
1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.
Following is the content of the modified module descriptorsrc/com.jtc/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.jtc.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>

Following is the content of the modified Style Sheet file war/HelloWorld.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;
}
.deckpanel {
border: 1px solid #BBBBBB;
padding: 3px;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="HelloWorld.css"/>
<script language="javascript" src="helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>DeckPanel Widget Demonstration</h1>
<div id="gwtContainer"></div>
</body>
</html>

Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of DeckPanel widget.

package com.jtc.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// Create DeckPanel widget
final DeckPanel deckPanel = new DeckPanel();
deckPanel.setSize("300px", "120px");
deckPanel.setStyleName("deckpanel");
// Create lables to add to deckpanel
Label label1 = new Label("This is first Page");
Label label2 = new Label("This is second Page");
Label label3 = new Label("This is third Page");
// Add labels to deckpanel
deckPanel.add(label1);
deckPanel.add(label2);
deckPanel.add(label3);
//show first label
deckPanel.showWidget(0);
//create button bar
HorizontalPanel buttonBar = new HorizontalPanel();
buttonBar.setSpacing(5);
// create button and add click handlers
// show different labels on click of different buttons
Button button1 = new Button("Page 1");
button1.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
deckPanel.showWidget(0);
}
});
Button button2 = new Button("Page 2");
button2.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
deckPanel.showWidget(1);
}
});
Button button3 = new Button("Page 3");
button3.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
deckPanel.showWidget(2);
}
});
buttonBar.add(button1);
buttonBar.add(button2);
buttonBar.add(button3);
VerticalPanel vPanel = new VerticalPanel();
vPanel.add(deckPanel);
vPanel.add(buttonBar);
// Add the widgets to the root panel.
RootPanel.get().add(vPanel);
}
}

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

GWT - Dock Panel Widget

Introduction

The DockPanel widget represents a panel that lays its child widgets out "docked" at its outer edges, and allows its last widget to take up the remaining space in its center.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.DockPanel class:

@Deprecated
public class DockPanel
extends CellPanel
implements HasAlignment

Class Constructors
S.N.Constructor & Description
1DockPanel() Constructor for DockPanel.
Class Methods
S.N.Function name & Description
1void add(Widget widget, DockPanel.DockLayoutConstant direction) Deprecated. Adds a widget to the specified edge of the dock.
2HasHorizontalAlignment.HorizontalAlignmentConstant getHorizontalAlignment() Deprecated. Gets the horizontal alignment.
3HasVerticalAlignment.VerticalAlignmentConstant getVerticalAlignment() Deprecated. Gets the vertical alignment.
4DockPanel.DockLayoutConstant getWidgetDirection(Widget w) Deprecated. Gets the layout direction of the given child widget.
5protected void onEnsureDebugId(java.lang.String baseID) Deprecated. DockPanel supports adding more than one cell in a direction, so an integer will be appended to the end of the debug id.
6boolean remove(Widget w) Deprecated. Removes a child widget.
7void setCellHeight(Widget w, java.lang.String height) Deprecated. Sets the height of the cell associated with the given widget, related to the panel as a whole.
8void set Cell Horizontal Alignment(Widget w, Has Horizontal Alignment. Horizontal Alignment Constant align) Deprecated. Sets the horizontal alignment of the given widget within its cell.
9void set Cell Vertical Alignment (Widget w, HasVertical Alignment. Vertical Alignment Constant align) Deprecated. Sets the vertical alignment of the given widget within its cell.
10void setCellWidth(Widget w, java.lang.String width) Deprecated. Sets the width of the cell associated with the given widget, related to the panel as a whole.
11void set Horizontal Alignment (Has Horizontal Alignment. Horizontal Alignment Constant align) Deprecated. Sets the default horizontal alignment to be used for widgets added to this panel.
12void setVerticalAlignment(HasVerticalAlignment.VerticalAlignmentConstant align) Deprecated. Sets the default vertical alignment to be used for widgets added to this panel.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Panel
  • com.google.gwt.user.client.ui.ComplexPanel
  • com.google.gwt.user.client.ui.CellPanel
  • java.lang.Object
Dockpanel Widget Example

This example will take you through simple steps to show usage of a DockPanel Widget in GWT. The following steps will help to you update the GWT application which we created in GWT - Create Application chapter:
StepDescription
1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.
Following is the content of the modified module descriptorsrc/com.jtc/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.jtc.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>

Following is the content of the modified Style Sheet file war/HelloWorld.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;
}
.dockpanel td {
border: 1px solid #BBBBBB;
padding: 3px;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="HelloWorld.css"/>
<script language="javascript" src="helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>DockPanel Widget Demonstration</h1>
<div id="gwtContainer"></div>
</body>
</html>

Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of DockPanel widget.

package com.jtc.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
DockPanel dockPanel = new DockPanel();
dockPanel.setStyleName("dockpanel");
dockPanel.setSpacing(4);
dockPanel.setHorizontalAlignment(DockPanel.ALIGN_CENTER);
// Add text all around
dockPanel.add(new HTML("This is the first north component."),
DockPanel.NORTH);
dockPanel.add(new HTML("This is the first south component."),
DockPanel.SOUTH);
dockPanel.add(new HTML("This is the east component."),
DockPanel.EAST);
dockPanel.add(new HTML("This is the west component."),
DockPanel.WEST);
dockPanel.add(new HTML("This is the second north component."),
DockPanel.NORTH);
dockPanel.add(new HTML("This is the second south component"),
DockPanel.SOUTH);
// Add scrollable text in the center
HTML contents = new HTML("This is a ScrollPanel contained"
+" at the center of a DockPanel. "
+" By putting some fairly large contents in the middle"
+" and setting its size explicitly, it becomes a scrollable area"
+" within the page, but without requiring the use of an IFRAME."
+" Here's quite a bit more meaningless text that will serve
primarily"
+" to make this thing scroll off the bottom of its visible area."
+" Otherwise, you might have to make it really, really"
+" small in order to see the nifty scroll bars!");
ScrollPanel scroller = new ScrollPanel(contents);
scroller.setSize("400px", "100px");
dockPanel.add(scroller, DockPanel.CENTER);
VerticalPanel vPanel = new VerticalPanel();
vPanel.add(dockPanel);
// Add the widgets to the root panel.
RootPanel.get().add(vPanel);
}
}

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce the following result:

GWT - HTML Panel Widget

Introduction

The HTMLPanel widget represents a panel that contains HTML, and which can attach child widgets to identified elements within that HTML.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.HTMLPanel class:

public class HTMLPanel
extends ComplexPanel

Class Constructors
S.N.Constructor & Description
1HTMLPanel(SafeHtml safeHtml) Initializes the panel's HTML from a given SafeHtml object.
2HTMLPanel(java.lang.String html) Creates an HTML panel with the specified HTML contents inside a DIV element.
3HTMLPanel(java.lang.String tag, java.lang.String html) Creates an HTML panel whose root element has the given tag, and with the specified HTML contents.
Class Methods
S.N.Function name & Description
1void add(Widget widget, Element elem)
Adds a child widget to the panel, contained within an HTML element.
2void add(Widget widget, java.lang.String id)
Adds a child widget to the panel, contained within the HTML element specified by a given id.
3void addAndReplaceElement(Widget widget, Element toReplace)
Adds a child widget to the panel, replacing the HTML element.
4void addAndReplaceElement(Widget widget, java.lang.String id)
Adds a child widget to the panel, replacing the HTML element specified by a given id.
5static java.lang.String createUniqueId()
A helper method for creating unique IDs for elements within dynamically- generated HTML.
6Element getElementById(java.lang.String id)
Finds an element within this panel by its id.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Panel
  • com.google.gwt.user.client.ui.ComplexPanel
  • java.lang.Object
Htmlpanel Widget Example

This example will take you through simple steps to show usage of a HTMLPanel Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter:
StepDescription
1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.
Following is the content of the modified module descriptor src/com.jtc/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.jtc.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>

Following is the content of the modified Style Sheet file war/HelloWorld.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;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="HelloWorld.css"/>
<script language="javascript" src="helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>HTMLPanel Widget Demonstration</h1>
<div id="gwtContainer"></div>
</body>
</html>

Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of HTMLPanel widget.

package com.jtc.client;
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 {
public void onModuleLoad() {
String htmlString = "This is a <b>HTMLPanel</b> containing"
+" html contents. "
+" <i>By putting some fairly large contents in the middle"
+" and setting its size explicitly, it becomes a scrollable area"
+" within the page, but without requiring the use of an IFRAME.</i>"
+" <u>Here's quite a bit more meaningless text that will serve"
+" to make this thing scroll off the bottom of its visible area."
+" Otherwise, you might have to make it really, really"
+" small in order to see the nifty scroll bars!</u>";
HTMLPanel htmlPanel = new HTMLPanel(htmlString);
DecoratorPanel panel = new DecoratorPanel();
panel.add(htmlPanel);
// Add the widgets to the root panel.
RootPanel.get().add(panel);
}
}

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result:

GWT - Tab Panel Widget

Introduction

The TabPanel widget represents panel that represents a tabbed set of pages, each of which contains another widget. Its child widgets are shown as the user selects the various tabs associated with them. The tabs can contain arbitrary HTML.

Class Declaration

Following is the declaration for com.google.gwt.user.client.ui.TabPanel class:

@Deprecated
public class TabPanel
extends Composite
implements TabListener, SourcesTabEvents,
HasWidgets, HasAnimation, IndexedPanel.ForIsWidget,
HasBeforeSelectionHandlers<java.lang.Integer>,
HasSelectionHandlers<java.lang.Integer>

Class Constructors
S.N.Constructor & Description
1TabPanel() Deprecated. Creates an empty tab panel.
Class Methods
S.N.Function name & Description
1void add(IsWidget w, IsWidget tabWidget) Deprecated. Convenience overload to allow IsWidget to be used directly.
2void add(IsWidget w, java.lang.String tabText) Deprecated. Convenience overload to allow IsWidget to be used directly.
3void add(IsWidget w, java.lang.String tabText, boolean asHTML) Deprecated. Convenience overload to allow IsWidget to be used directly.
4void add(Widget w) Deprecated. Adds a child widget.
5void add(Widget w, java.lang.String tabText) Deprecated. Adds a widget to the tab panel.
6void add(Widget w, java.lang.String tabText, boolean asHTML) Deprecated. Adds a widget to the tab panel.
7void add(Widget w, Widget tabWidget) Deprecated. Adds a widget to the tab panel.
8Handler Registration add Before Selection Handler (Before Selection Handler<java.lang.Integer> handler) Deprecated. Adds a BeforeSelectionEvent handler.
9Handler Registration add Selection Handler (Selection Handler <java.lang.Integer> handler) Deprecated. Adds a SelectionEvent handler.
10void add Tab Listener(TabListener listener) Deprecated. Use add Before Selection Handler (com.google.gwt.event.logical.shared.Before Selection Handler) and add Selection Handler (com.google.gwt.event.logical.shared.Selection Handler) instead
11void clear() Deprecated. Removes all child widgets.
12protected SimplePanel createTabTextWrapper() Deprecated. Create a SimplePanel that will wrap the contents in a tab.
13DeckPanel getDeckPanel() Deprecated. Gets the deck panel within this tab panel.
14TabBar getTabBar() Deprecated. Gets the tab bar within this tab panel.
15Widget getWidget(int index) Deprecated. Gets the child widget at the specified index.
16int getWidgetCount() Deprecated. Gets the number of child widgets in this panel.
17int getWidgetIndex(IsWidget child) Deprecated. Convenience overload to allow IsWidget to be used directly.
18int getWidgetIndex(Widget widget) Deprecated. Gets the index of the specified child widget.
19void insert(IsWidget widget, IsWidget tabWidget, int beforeIndex) Deprecated. Convenience overload to allow IsWidget to be used directly.
20void insert(IsWidget widget, java.lang.String tab Text, boolean asHTML, int before Index) Deprecated. Convenience overload to allow IsWidget to be used directly.
21void insert(IsWidget widget, java.lang.String tabText, int beforeIndex) Deprecated. Convenience overload to allow IsWidget to be used directly.
22void insert(Widget widget, java.lang.String tabText, boolean asHTML, int beforeIndex) Deprecated. Inserts a widget into the tab panel.
23void insert(Widget widget, java.lang.String tabText, int beforeIndex) Deprecated. Inserts a widget into the tab panel.
24void insert(Widget widget, Widget tabWidget, int beforeIndex) Deprecated. Inserts a widget into the tab panel.
25boolean isAnimationEnabled() Deprecated. Returns true if animations are enabled, false if not.
26java.util.Iterator<Widget> iterator() Deprecated. Gets an iterator for the contained widgets.
27boolean on Before Tab Selected(Sources Tab Events sender, int tab Index) Deprecated. Use Before Selection Handler.on Before Selection(com.google.gwt.event.logical.shared.Before Selection Event) instead
28protected void onEnsureDebugId(java.lang.String baseID) Deprecated. Affected Elements: -bar = The tab bar. -bar-tab# = The element containing the content of the tab itself. -bar-tab-wrapper# = The cell containing the tab at the index. -bottom = The panel beneath the tab bar.
29void onTabSelected(SourcesTabEvents sender, int tabIndex) Deprecated. Use SelectionHandler.onSelection(com.google.gwt.event.logical.shared.SelectionEvent) instead
30boolean remove(int index) Deprecated. Removes the widget at the specified index.
31boolean remove(Widget widget) Deprecated. Removes the given widget, and its associated tab.
32void removeTabListener(TabListener listener) Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by and add*Handler method instead
33void selectTab(int index) Deprecated. Programmatically selects the specified tab and fires events.
34void selectTab(int index, boolean fireEvents) Deprecated. Programmatically selects the specified tab.
35void setAnimationEnabled(boolean enable) Deprecated. Enable or disable animations.
Methods Inherited

This class inherits methods from the following classes:
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Composite
  • java.lang.Object
Tab Panel Widget Example

This example will take you through simple steps to show usage of a TabPanel Widget in GWT. The following steps will help to you update the GWT application which we created in GWT - Create Application chapter:
  • StepDescription
    1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
    2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
    3Compile and run the application to verify the result of the implemented logic.
    Following is the content of the modified module descriptorsrc/com.jtc/HelloWorld.gwt.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='helloworld'>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User'/>
    <!-- Inherit the default GWT style sheet. -->
    <inherits name='com.google.gwt.user.theme.clean.Clean'/>
    <!-- Specify the app entry point class. -->
    <entry-point class='com.jtc.client.HelloWorld'/>
    <!-- Specify the paths for translatable code -->
    <source path='client'/>
    <source path='shared'/>
    </module>

    Following is the content of the modified Style Sheet file war/HelloWorld.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;
    }

    Following is the content of the modified HTML host file war/HelloWorld.html.

    <html>
    <head>
    <title>Hello World</title>
    <link rel="stylesheet" href="HelloWorld.css"/>
    <script language="javascript" src="helloworld/helloworld.nocache.js">
    </script>
    </head>
    <body>
    <h1>TabPanel Widget Demonstration</h1>
    <div id="gwtContainer"></div>
    </body>
    </html>

    Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of TabPanel widget.

    package com.jtc.client;
    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.Label;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.TabPanel;
    public class HelloWorld implements EntryPoint {
    public void onModuleLoad() {
    //Create an empty tab panel
    TabPanel tabPanel = new TabPanel();
    //create contents for tabs of tabpanel
    Label label1 = new Label("This is contents of TAB 1");
    label1.setHeight("200");
    Label label2 = new Label("This is contents of TAB 2");
    label2.setHeight("200");
    Label label3 = new Label("This is contents of TAB 3");
    label3.setHeight("200");
    //create titles for tabs
    String tab1Title = "TAB 1";
    String tab2Title = "TAB 2";
    String tab3Title = "TAB 3";
    //create tabs
    tabPanel.add(label1, tab1Title);
    tabPanel.add(label2, tab2Title);
    tabPanel.add(label3, tab3Title);
    //select first tab
    tabPanel.selectTab(0);
    //set width if tabpanel
    tabPanel.setWidth("400");
    // Add the widgets to the root panel.
    RootPanel.get().add(tabPanel);
    }
    }

    Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

    GWT - Composite Widget

    Introduction

    The Composite widget is a type of widget that can wrap another widget, hiding the wrapped widget's methods. When added to a panel, a composite behaves exactly as if the widget it wraps had been added. The composite is useful for creating a single widget out of an aggregate of multiple other widgets contained in a single panel.

    Class Declaration

    Following is the declaration for com.google.gwt.user.client.ui.Composite class:

    public abstract class Composite
    extends Widget

    Class Constructors
    S.N.Constructor & Description
    1Composite()
    Class Methods
    S.N.Function name & Description
    1protected Widget getWidget() Provides subclasses access to the topmost widget that defines this composite.
    2protected void initWidget(Widget widget) Sets the widget to be wrapped by the composite.
    3boolean isAttached() Determines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).
    4protected void onAttach() This method is called when a widget is attached to the browser's document.
    5void onBrowserEvent(Event event) Fired whenever a browser event is received.
    6protected void onDetach() This method is called when a widget is detached from the browser's document.
    7protected void setWidget(Widget widget) Deprecated. Use initWidget(Widget) instead
    Methods Inherited

    This class inherits methods from the following classes:
    • com.google.gwt.user.client.ui.UIObject
    • com.google.gwt.user.client.ui.Widget
    • java.lang.Object
    Composite Widget Example

    This example will take you through simple steps to show usage of a Composite Widget in GWT. The following steps will help to you update the GWT application which we created in GWT - Create Application chapter:
    StepDescription
    1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
    2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
    3Compile and run the application to verify the result of the implemented logic.
    Following is the content of the modified module descriptor src/com.jtc/HelloWorld.gwt.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='helloworld'>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User'/>
    <!-- Inherit the default GWT style sheet. -->
    <inherits name='com.google.gwt.user.theme.clean.Clean'/>
    <!-- Specify the app entry point class. -->
    <entry-point class='com.jtc.client.HelloWorld'/>
    <!-- Specify the paths for translatable code -->
    <source path='client'/>
    <source path='shared'/>
    </module>

    Following is the content of the modified Style Sheet file war/HelloWorld.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;
    }

    Following is the content of the modified HTML host file war/HelloWorld.html.

    <html>
    <head>
    <title>Hello World</title>
    <link rel="stylesheet" href="HelloWorld.css"/>
    <script language="javascript" src="helloworld/helloworld.nocache.js">
    </script>
    </head>
    <body>
    <h1>Composite Widget Demonstration</h1>
    <div id="gwtContainer"></div>
    </body>
    </html>

    Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of Composite widget.

    package com.jtc.client;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.user.client.ui.CheckBox;
    import com.google.gwt.user.client.ui.Composite;
    import com.google.gwt.user.client.ui.DecoratorPanel;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.TextBox;
    import com.google.gwt.user.client.ui.VerticalPanel;
    public class HelloWorld implements EntryPoint {
    /**
    * A composite of a TextBox and a CheckBox that optionally enables it.
    */
    private static class OptionalTextBox extends Composite implements
    ClickHandler {
    private TextBox textBox = new TextBox();
    private CheckBox checkBox = new CheckBox();
    /**
    * Constructs an OptionalTextBox with the given caption
    * on the check.
    * @param caption the caption to be displayed with the check box
    */
    public OptionalTextBox(String caption) {
    // Place the check above the text box using a vertical panel.
    VerticalPanel panel = new VerticalPanel();
    // panel.setBorderWidth(1);
    panel.setSpacing(10);
    panel.add(checkBox);
    panel.add(textBox);
    textBox.setWidth("200");
    // Set the check box's caption, and check it by default.
    checkBox.setText(caption);
    checkBox.setValue(true);
    checkBox.addClickHandler(this);
    DecoratorPanel decoratorPanel = new DecoratorPanel();
    decoratorPanel.add(panel);
    // All composites must call initWidget() in their constructors.
    initWidget(decoratorPanel);
    }
    public void onClick(ClickEvent event) {
    if (event.getSource() == checkBox) {
    // When the check box is clicked,
    //update the text box's enabled state.
    textBox.setEnabled(checkBox.getValue());
    }
    }
    }
    public void onModuleLoad() {
    // Create an optional text box and add it to the root panel.
    OptionalTextBox otb = new OptionalTextBox("Check this to enable me");
    RootPanel.get().add(otb);
    }
    }

    Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

    GWT - Simple Panel Widget

    Introduction

    The SimplePanel widget represents a base class for panels that contain only one widget.

    Class Declaration

    Following is the declaration for com.google.gwt.user.client.ui.SimplePanel class:

    public class SimplePanel
    extends Panel
    implements HasOneWidget

    Class Constructors
    S.N.Constructor & Description
    1SimplePanel() Creates an empty panel that uses a DIV for its contents.
    2protected SimplePanel(Element elem) Creates an empty panel that uses the specified browser element for its contents.
    Class Methods
    S.N.Function name & Description
    1void add(Widget w) Adds a widget to this panel.
    2protected Element getContainerElement() Override this method to specify that an element other than the root element be the container for the panel's child widget.
    3Widget getWidget() Gets the panel's child widget.
    4java.util.Iterator<Widget> iterator() Gets an iterator for the contained widgets.
    5boolean remove(Widget w) Removes a child widget.
    6void setWidget(IsWidget w) Set the only widget of the receiver, replacing the previous widget if there was one.
    7void setWidget(Widget w) Sets this panel's widget.
    Methods Inherited

    This class inherits methods from the following classes:
    • com.google.gwt.user.client.ui.UIObject
    • com.google.gwt.user.client.ui.Widget
    • com.google.gwt.user.client.ui.Panel
    • java.lang.Object
    Simple Panel Widget Example

    This example will take you through simple steps to show usage of a SimplePanel Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter:
    StepDescription
    1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
    2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
    3Compile and run the application to verify the result of the implemented logic.
    Following is the content of the modified module descriptor src/com.jtc/HelloWorld.gwt.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='helloworld'>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User'/>
    <!-- Inherit the default GWT style sheet. -->
    <inherits name='com.google.gwt.user.theme.clean.Clean'/>
    <!-- Specify the app entry point class. -->
    <entry-point class='com.jtc.client.HelloWorld'/>
    <!-- Specify the paths for translatable code -->
    <source path='client'/>
    <source path='shared'/>
    </module>

    Following is the content of the modified Style Sheet file war/HelloWorld.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;
    }

    Following is the content of the modified HTML host file war/HelloWorld.html.

    <html>
    <head>
    <title>Hello World</title>
    <link rel="stylesheet" href="HelloWorld.css"/>
    <script language="javascript" src="helloworld/helloworld.nocache.js">
    </script>
    </head>
    <body>
    <h1>SimplePanel Widget Demonstration</h1>
    <div id="gwtContainer"></div>
    </body>
    </html>

    Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of SimplePanel widget.

    package com.jtc.client;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.DecoratorPanel;
    import com.google.gwt.user.client.ui.Label;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.SimplePanel;
    public class HelloWorld implements EntryPoint {
    public void onModuleLoad() {
    // Create a Simple Panel
    SimplePanel simplePanel = new SimplePanel();
    Label label = new Label("A Simple Label.");
    //add label to simple panel
    simplePanel.add(label);
    //set height and width of simple panel
    simplePanel.setHeight("200");
    simplePanel.setWidth("200");
    DecoratorPanel decoratorPanel = new DecoratorPanel();
    decoratorPanel.add(simplePanel);
    // Add the widgets to the root panel.
    RootPanel.get().add(decoratorPanel);
    }
    }

    Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

    GWT - Scroll Panel Widget

    Introduction

    The Scroll Panel widget represents a simple panel that wraps its contents in a scrollable area.

    Class Declaration

    Following is the declaration for com.google.gwt.user.client.ui.ScrollPanel class:

    public class ScrollPanel
    extends SimplePanel
    implements SourcesScrollEvents, HasScrollHandlers,
    RequiresResize, ProvidesResize

    Class Constructors
    S.N.Constructor & Description
    1ScrollPanel() Creates an empty scroll panel.
    2ScrollPanel(Widget child) Creates a new scroll panel with the given child widget.
    Class methods
    S.N.Function name & Description
    1HandlerRegistration addScrollHandler(ScrollHandler handler) Adds a ScrollEvent handler.
    2void addScrollListener(ScrollListener listener) Deprecated. Use addScrollHandler(com.google.gwt.event.dom.client.ScrollHandler) instead
    3void ensureVisible(UIObject item) Ensures that the specified item is visible, by adjusting the panel's scroll position.
    4protected Element getContainerElement() Override this method to specify that an element other than the root element be the container for the panel's child widget.
    5int getHorizontalScrollPosition() Gets the horizontal scroll position.
    6int getScrollPosition() Gets the vertical scroll position.
    7void onResize() This method must be called whenever the implementor's size has been modified.
    8void removeScrollListener(ScrollListener listener) Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addScrollHandler(com.google.gwt.event.dom.client.ScrollHandler) instead
    9void scrollToBottom() Scroll to the bottom of this panel.
    10void scrollToLeft() Scroll to the far left of this panel.
    11void scrollToRight() Scroll to the far right of this panel.
    12void scrollToTop() Scroll to the top of this panel.
    13void setAlwaysShowScrollBars(boolean alwaysShow) Sets whether this panel always shows its scroll bars, or only when necessary.
    14void setHeight(java.lang.String height) Sets the object's height.
    15void setHorizontalScrollPosition(int position) Sets the horizontal scroll position.
    16void setScrollPosition(int position) Sets the vertical scroll position.
    17void setSize(java.lang.String width, java.lang.String height) Sets the object's size.
    18void setWidth(java.lang.String width) Sets the object's width.
    Methods Inherited

    This class inherits methods from the following classes:
    • com.google.gwt.user.client.ui.UIObject
    • com.google.gwt.user.client.ui.Widget
    • com.google.gwt.user.client.ui.Panel
    • com.google.gwt.user.client.ui.SimplePanel
    • java.lang.Object
    Scroll Panel Widget Example

    This example will take you through simple steps to show usage of a ScrollPanel Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter:
    StepDescription
    1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
    2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
    3Compile and run the application to verify the result of the implemented logic.
    Following is the content of the modified module descriptorsrc/com.jtc/HelloWorld.gwt.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='helloworld'>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User'/>
    <!-- Inherit the default GWT style sheet. -->
    <inherits name='com.google.gwt.user.theme.clean.Clean'/>
    <!-- Specify the app entry point class. -->
    <entry-point class='com.jtc.client.HelloWorld'/>
    <!-- Specify the paths for translatable code -->
    <source path='client'/>
    <source path='shared'/>
    </module>

    Following is the content of the modified Style Sheet file war/HelloWorld.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;
    }

    Following is the content of the modified HTML host file war/HelloWorld.html.

    <html>
    <head>
    <title>Hello World</title>
    <link rel="stylesheet" href="HelloWorld.css"/>
    <script language="javascript" src="helloworld/helloworld.nocache.js">
    </script>
    </head>
    <body>
    <h1>ScrollPanel Widget Demonstration</h1>
    <div id="gwtContainer"></div>
    </body>
    </html>

    Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of ScrollPanel widget.

    package com.jtc.client;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.DecoratorPanel;
    import com.google.gwt.user.client.ui.HTML;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.ScrollPanel;
    public class HelloWorld implements EntryPoint {
    public void onModuleLoad() {
    // Create scrollable text
    HTML contents = new HTML("This is a ScrollPanel."
    +" By putting some fairly large contents in the middle"
    +" and setting its size explicitly, it becomes a scrollable area"
    +" within the page, but without requiring the use of an IFRAME."
    +" Here's quite a bit more meaningless text that will serve primarily"
    +" to make this thing scroll off the bottom of its visible area."
    +" Otherwise, you might have to make it really, really"
    +" small in order to see the nifty scroll bars!");
    //create scrollpanel with content
    ScrollPanel scrollPanel = new ScrollPanel(contents);
    scrollPanel.setSize("400px", "100px");
    DecoratorPanel decoratorPanel = new DecoratorPanel();
    decoratorPanel.add(scrollPanel);
    // Add the widgets to the root panel.
    RootPanel.get().add(decoratorPanel);
    }
    }

    Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

    GWT - Focus Panel Widget

    Introduction

    The Focus Panel widget represents a simple panel that makes its contents focusable, and adds the ability to catch mouse and keyboard events.

    Class Declaration

    Following is the declaration for com.google.gwt.user.client.ui.FocusPanel class:

    public class FocusPanel
    extends SimplePanel
    implements HasFocus, SourcesClickEvents,
    SourcesMouseEvents, SourcesMouseWheelEvents,
    HasAllMouseHandlers, HasClickHandlers,
    HasDoubleClickHandlers, HasAllKeyHandlers,
    HasAllFocusHandlers

    Class Constructors
    S.N.Constructor & Description
    1FocusPanel() Creates an empty focus panel.
    2FocusPanel(Widget child) Creates a new focus panel with the given child widget.
    Class Methods
    S.N.Function name & Description
    1HandlerRegistration addBlurHandler(BlurHandler handler) Adds a BlurEvent handler.
    2HandlerRegistration addClickHandler(ClickHandler handler) Adds a ClickEvent handler.
    3void addClickListener(ClickListener listener) Deprecated. Use addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead
    4HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler) Adds a DoubleClickEvent handler.
    5HandlerRegistration addFocusHandler(FocusHandler handler) Adds a FocusEvent handler.
    6void addFocusListener(FocusListener listener) Deprecated. Use addFocusHandler(com.google.gwt.event.dom.client.FocusHandler) instead
    7void addKeyboardListener(KeyboardListener listener) Deprecated. Use addKeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler), addKeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) and addKeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) instead
    8HandlerRegistration addKeyDownHandler(KeyDownHandler handler) Adds a KeyDownEvent handler.
    9HandlerRegistration addKeyPressHandler(KeyPressHandler handler) Adds a KeyPressEvent handler.
    10HandlerRegistration addKeyUpHandler(KeyUpHandler handler) Adds a KeyUpEvent handler.
    11HandlerRegistration addMouseDownHandler(MouseDownHandler handler) Adds a MouseDownEvent handler.
    12void addMouseListener(MouseListener listener) Deprecated. Use addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler), addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler), addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler), addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler) and addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) instead
    13HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) Adds a MouseMoveEvent handler.
    14HandlerRegistration addMouseOutHandler(MouseOutHandler handler) Adds a MouseOutEvent handler.
    15HandlerRegistration addMouseOverHandler(MouseOverHandler handler) Adds a MouseOverEvent handler.
    16HandlerRegistration addMouseUpHandler(MouseUpHandler handler) Adds a MouseUpEvent handler.
    17HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) Adds a MouseWheelEvent handler.
    18void addMouseWheelListener(MouseWheelListener listener) Deprecated. Use addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler) instead
    19int getTabIndex() Gets the widget's position in the tab index.
    20void removeClickListener(ClickListener listener) Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead
    21void removeFocusListener(FocusListener listener) Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addFocusHandler(com.google.gwt.event.dom.client.FocusHandler) instead
    22void removeKeyboardListener(KeyboardListener listener) Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by an add*Handler method instead
    23void removeMouseListener(MouseListener listener) Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by an add*Handler method instead
    24void removeMouseWheelListener(MouseWheelListener listener) Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler) instead
    25void setAccessKey(char key) Sets the widget's 'access key'.
    26void setFocus(boolean focused) Explicitly focus/unfocus this widget.
    27void setTabIndex(int index) Sets the widget's position in the tab index.
    Methods Inherited

    This class inherits methods from the following classes:
    • com.google.gwt.user.client.ui.UIObject
    • com.google.gwt.user.client.ui.Widget
    • com.google.gwt.user.client.ui.Panel
    • com.google.gwt.user.client.ui.SimplePanel
    • java.lang.Object
    Focus Panel Widget Example

    This example will take you through simple steps to show usage of a FocusPanel Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter:
    StepDescription
    1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
    2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
    3Compile and run the application to verify the result of the implemented logic.
    Following is the content of the modified module descriptorsrc/com.jtc/HelloWorld.gwt.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='helloworld'>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User'/>
    <!-- Inherit the default GWT style sheet. -->
    <inherits name='com.google.gwt.user.theme.clean.Clean'/>
    <!-- Specify the app entry point class. -->
    <entry-point class='com.jtc.client.HelloWorld'/>
    <!-- Specify the paths for translatable code -->
    <source path='client'/>
    <source path='shared'/>
    </module>

    Following is the content of the modified Style Sheet file war/HelloWorld.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;
    }

    Following is the content of the modified HTML host file war/HelloWorld.html.

    <html>
    <head>
    <title>Hello World</title>
    <link rel="stylesheet" href="HelloWorld.css"/>
    <script language="javascript" src="helloworld/helloworld.nocache.js">
    </script>
    </head>
    <body>
    <h1>FocusPanel Widget Demonstration</h1>
    <div id="gwtContainer"></div>
    </body>
    </html>

    Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of FocusPanel widget.

    package com.jtc.client;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.DecoratorPanel;
    import com.google.gwt.user.client.ui.FocusPanel;
    import com.google.gwt.user.client.ui.HTML;
    import com.google.gwt.user.client.ui.RootPanel;
    public class HelloWorld implements EntryPoint {
    public void onModuleLoad() {
    // Create text
    HTML contents = new HTML("This is a FocusPanel."
    +" Click on the panel and it will attain focus.");
    //create focus panel with content
    FocusPanel focusPanel = new FocusPanel(contents);
    focusPanel.setSize("400px", "100px");
    DecoratorPanel decoratorPanel = new DecoratorPanel();
    decoratorPanel.add(focusPanel);
    // Add the widgets to the root panel.
    RootPanel.get().add(decoratorPanel);
    }
    }

    Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

    GWT - Form Panel Widget

    Introduction

    The Form Panel widget represents a panel that wraps its contents in an HTML <FORM> element.

    Class Declaration

    Following is the declaration for com.google.gwt.user.client.ui.FormPanel class:

    public class FormPanel
    extends SimplePanel
    implements FiresFormEvents,
    com.google.gwt.user.client.ui.impl.FormPanelImplHost

    Class Constructors
    S.N.Constructor & Description
    1FormPanel() Creates a new FormPanel.
    2protected FormPanel(Element element) This constructor may be used by subclasses to explicitly use an existing element.
    3protected FormPanel(Element element, boolean createIFrame) This constructor may be used by subclasses to explicitly use an existing element.
    4FormPanel(NamedFrame frameTarget) Creates a FormPanel that targets a NamedFrame.
    5FormPanel(java.lang.String target) Creates a new FormPanel.
    Class Methods
    S.N.Function name & Description
    1void add Form Handler (FormHandler handler)
    Deprecated. Use add Submit Complete Handler (com.google.gwt.user.client.ui.Form Panel.Submit Complete Handler) and add Submit Handler (com.google.gwt.user.client.ui.Form Panel.Submit Handler) instead
    2Handler Registration addSubmit Complete Handler (FormPanel.SubmitCompleteHandler handler)
    Adds a FormPanel.Submit Complete Event handler.
    3HandlerRegistration addSubmitHandler(FormPanel.SubmitHandler handler)
    Adds a FormPanel.SubmitEvent handler.
    4java.lang.String getAction()
    Gets the 'action' associated with this form.
    5java.lang.String getEncoding()
    Gets the encoding used for submitting this form.
    6java.lang.String getMethod()
    Gets the HTTP method used for submitting this form.
    7java.lang.String getTarget()
    Gets the form's 'target'.
    8protected void onAttach()
    This method is called when a widget is attached to the browser's document.
    9protected void onDetach()
    This method is called when a widget is detached from the browser's document.
    10boolean onFormSubmit()
    Fired when a form is submitted.
    11void onFrameLoad()
    12void removeFormHandler(FormHandler handler)
    Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by and add*Handler method instead
    13void reset()
    Resets the form, clearing all fields.
    14void setAction(java.lang.String url)
    Sets the 'action' associated with this form.
    15void setEncoding(java.lang.String encodingType)
    Sets the encoding used for submitting this form.
    16void setMethod(java.lang.String method)
    Sets the HTTP method used for submitting this form.
    17void submit()
    Submits the form.
    18static FormPanel wrap(Element element)
    Creates a FormPanel that wraps an existing <form> element.
    19static FormPanel wrap(Element element, boolean createIFrame)
    Creates a FormPanel that wraps an existing <form> element.
    Methods Inherited

    This class inherits methods from the following classes:
    • com.google.gwt.user.client.ui.UIObject
    • com.google.gwt.user.client.ui.Widget
    • com.google.gwt.user.client.ui.Panel
    • com.google.gwt.user.client.ui.SimplePanel
    • java.lang.Object
    Formpanel Widget Example

    This example will take you through simple steps to show usage of a FormPanel Widget in GWT. The following steps will help to you update the GWT application which we created in GWT - Create Application chapter:
    StepDescription
    1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
    2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
    3Compile and run the application to verify the result of the implemented logic.
    Following is the content of the modified module descriptor src/com.jtc/HelloWorld.gwt.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='helloworld'>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User'/>
    <!-- Inherit the default GWT style sheet. -->
    <inherits name='com.google.gwt.user.theme.clean.Clean'/>
    <!-- Specify the app entry point class. -->
    <entry-point class='com.jtc.client.HelloWorld'/>
    <!-- Specify the paths for translatable code -->
    <source path='client'/>
    <source path='shared'/>
    </module>

    Following is the content of the modified Style Sheet file war/HelloWorld.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;
    }

    Following is the content of the modified HTML host file war/HelloWorld.html.

    <html>
    <head>
    <title>Hello World</title>
    <link rel="stylesheet" href="HelloWorld.css"/>
    <script language="javascript" src="helloworld/helloworld.nocache.js">
    </script>
    </head>
    <body>
    <h1>FormPanel Widget Demonstration</h1>
    <div id="gwtContainer"></div>
    </body>
    </html>

    Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of FormPanel widget.

    package com.jtc.client;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.user.client.Window;
    import com.google.gwt.user.client.ui.Button;
    import com.google.gwt.user.client.ui.DecoratorPanel;
    import com.google.gwt.user.client.ui.FileUpload;
    import com.google.gwt.user.client.ui.FormPanel;
    import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
    import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
    import com.google.gwt.user.client.ui.ListBox;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.TextBox;
    import com.google.gwt.user.client.ui.VerticalPanel;
    public class HelloWorld implements EntryPoint {
    public void onModuleLoad() {
    // Create a FormPanel and point it at a service.
    final FormPanel form = new FormPanel();
    form.setAction("/myFormHandler");
    // Because we're going to add a FileUpload widget,
    // we'll need to set the form to use the POST method,
    // and multipart MIME encoding.
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);
    // Create a panel to hold all of the form widgets.
    VerticalPanel panel = new VerticalPanel();
    panel.setSpacing(10);
    form.setWidget(panel);
    // Create a TextBox, giving it a name so that it will be submitted.
    final TextBox tb = new TextBox();
    tb.setWidth("220");
    tb.setName("textBoxFormElement");
    panel.add(tb);
    // Create a ListBox, giving it a name and
    // some values to be associated with its options.
    ListBox lb = new ListBox();
    lb.setName("listBoxFormElement");
    lb.addItem("item1", "item1");
    lb.addItem("item2", "item2");
    lb.addItem("item3", "item3");
    lb.setWidth("220");
    panel.add(lb);
    // Create a FileUpload widget.
    FileUpload upload = new FileUpload();
    upload.setName("uploadFormElement");
    panel.add(upload);
    // Add a 'submit' button.
    panel.add(new Button("Submit", new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
    form.submit();
    }
    }));
    // Add an event handler to the form.
    form.addSubmitHandler(new FormPanel.SubmitHandler() {
    @Override
    public void onSubmit(SubmitEvent event) {
    // This event is fired just before the form is submitted.
    // We can take this opportunity to perform validation.
    if (tb.getText().length() == 0) {
    Window.alert("The text box must not be empty");
    event.cancel();
    }
    }
    });
    form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
    @Override
    public void onSubmitComplete(SubmitCompleteEvent event) {
    // When the form submission is successfully completed,
    // this event is fired. Assuming the service returned
    // a response of type text/html, we can get the result
    // here.
    Window.alert(event.getResults());
    }
    });
    DecoratorPanel decoratorPanel = new DecoratorPanel();
    decoratorPanel.add(form);
    // Add the widgets to the root panel.
    RootPanel.get().add(decoratorPanel);
    }
    }

    Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

    GWT - Popup Panel Widget

    Introduction

    The PopupPanel widget represents a panel that can pop up over other widgets. It overlays the browser's client area (and any previously-created popups).

    Class Declaration

    Following is the declaration for com.google.gwt.user.client.ui.PopupPanel class:

    public class PopupPanel
    extends SimplePanel
    implements SourcesPopupEvents, EventPreview,
    HasAnimation, HasCloseHandlers<PopupPanel>

    Class Constructors
    S.N.Constructor & Description
    1PopupPanel() Creates an empty popup panel.
    2PopupPanel(boolean autoHide) Creates an empty popup panel, specifying its auto-hide property.
    3PopupPanel(boolean autoHide, boolean modal) Creates an empty popup panel, specifying its auto-hide and modal properties.
    Class Methods
    S.N.Function name & Description
    1void addAutoHidePartner(Element partner) Mouse events that occur within an autoHide partner will not hide a panel set to autoHide.
    2HandlerRegistration addCloseHandler(CloseHandler handler) Adds a CloseEvent handler.
    3void addPopupListener(PopupListener listener) Deprecated. Use addCloseHandler(com.google.gwt.event.logical.shared.CloseHandler) instead
    4void center() Centers the popup in the browser window and shows it.
    5protected Element getContainerElement() Override this method to specify that an element other than the root element be the container for the panel's child widget.
    6protected Element getGlassElement() Get the glass element used by this PopupPanel.
    7java.lang.String getGlassStyleName() Gets the style name to be used on the glass element.
    8int getOffsetHeight() Gets the panel's offset height in pixels.
    9int getOffsetWidth() Gets the panel's offset width in pixels.
    10int getPopupLeft() Gets the popup's left position relative to the browser's client area.
    11int getPopupTop() Gets the popup's top position relative to the browser's client area.
    12protected Element getStyleElement() Template method that returns the element to which style names will be applied.
    13java.lang.String getTitle() Gets the title associated with this object.
    14void hide() Hides the popup and detaches it from the page.
    15void hide(boolean autoClosed) Hides the popup and detaches it from the page.
    16boolean isAnimationEnabled() Returns true if animations are enabled, false if not.
    17boolean isAutoHideEnabled() Returns true if the popup should be automatically hidden when the user clicks outside of it.
    18boolean isAutoHideOnHistoryEventsEnabled() Returns true if the popup should be automatically hidden when the history token changes, such as when the user presses the browser's back button.
    19boolean isGlassEnabled() Returns true if a glass element will be displayed under the PopupPanel.
    20boolean isModal() Returns true if keyboard or mouse events that do not target the PopupPanel or its children should be ignored.
    21boolean isPreviewingAllNativeEvents() Returns true if the popup should preview all native events, even if the event has already been consumed by another popup.
    22boolean isShowing() Determines whether or not this popup is showing.
    23boolean isVisible() Determines whether or not this popup is visible.
    24boolean onEventPreview(Event event) Deprecated. Use onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent) instead
    25boolean onKeyDownPreview(char key, int modifiers) Deprecated. Use onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent) instead
    26boolean onKeyPressPreview(char key, int modifiers) Deprecated. Use onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreview
    27boolean onKeyUpPreview(char key, int modifiers) Deprecated. Use onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent) instead
    28protected void onPreviewNativeEvent(Event.NativePreviewEvent event)
    29protected void onUnload() This method is called immediately before a widget will be detached from the browser's document.
    30void removeAutoHidePartner(Element partner) Remove an autoHide partner.
    31void removePopupListener(PopupListener listener) Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addCloseHandler(com.google.gwt.event.logical.shared.CloseHandler) instead
    32void setAnimationEnabled(boolean enable) Enable or disable animations.
    33void setAutoHideEnabled(boolean autoHide) Enable or disable the autoHide feature.
    34void setAutoHideOnHistoryEventsEnabled(boolean enabled) Enable or disable autoHide on history change events.
    35void setGlassEnabled(boolean enabled) When enabled, the background will be blocked with a semi-transparent pane the next time it is shown.
    36void setGlassStyleName(java.lang.String glassStyleName) Sets the style name to be used on the glass element.
    37void setHeight(java.lang.String height) Sets the height of the panel's child widget.
    38void setModal(boolean modal) When the popup is modal, keyboard or mouse events that do not target the PopupPanel or its children will be ignored.
    39void setPopupPosition(int left, int top) Sets the popup's position relative to the browser's client area.
    40void setPopupPositionAndShow(PopupPanel.PositionCallback callback) Sets the popup's position using a PopupPanel.PositionCallback, and shows the popup.
    41void setPreviewingAllNativeEvents(boolean previewAllNativeEvents) When enabled, the popup will preview all native events, even if another popup was opened after this one.
    42void setTitle(java.lang.String title) Sets the title associated with this object.
    43void setVisible(boolean visible) Sets whether this object is visible.
    44void setWidget(Widget w) Sets this panel's widget.
    45void setWidth(java.lang.String width) Sets the width of the panel's child widget.
    46void show() Shows the popup and attach it to the page.
    47void showRelativeTo(UIObject target) Normally, the popup is positioned directly below the relative target, with its left edge aligned with the left edge of the target.
    Methods Inherited

    This class inherits methods from the following classes:
    • com.google.gwt.user.client.ui.UIObject
    • com.google.gwt.user.client.ui.Widget
    • com.google.gwt.user.client.ui.Panel
    • com.google.gwt.user.client.ui.SimplePanel
    • java.lang.Object
    Popuppanel Widget Example

    This example will take you through simple steps to show usage of a PopupPanel Widget in GWT. The following steps will help to you update the GWT application which we created in GWT - Create Application chapter:
    StepDescription
    1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
    2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
    3Compile and run the application to verify the result of the implemented logic.
    Following is the content of the modified module descriptorsrc/com.jtc/HelloWorld.gwt.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='helloworld'>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User'/>
    <!-- Inherit the default GWT style sheet. -->
    <inherits name='com.google.gwt.user.theme.clean.Clean'/>
    <!-- Specify the app entry point class. -->
    <entry-point class='com.jtc.client.HelloWorld'/>
    <!-- Specify the paths for translatable code -->
    <source path='client'/>
    <source path='shared'/>
    </module>

    Following is the content of the modified Style Sheet file war/HelloWorld.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;
    }
    .gwt-PopupPanel {
    border: 3px solid #000000;
    padding: 3px;
    background: white;
    }
    .gwt-PopupPanelGlass {
    background-color: #000;
    opacity: 0.3;
    filter: alpha(opacity=30);
    }
    .gwt-PopupPanel .popupContent {
    border: none;
    padding: 3px;
    background: gray;
    }

    Following is the content of the modified HTML host file war/HelloWorld.html.

    <html>
    <head>
    <title>Hello World</title>
    <link rel="stylesheet" href="HelloWorld.css"/>
    <script language="javascript" src="helloworld/helloworld.nocache.js">
    </script>
    </head>
    <body>
    <h1>PopupPanel Widget Demonstration</h1>
    <div id="gwtContainer"></div>
    </body>
    </html>

    Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of PopupPanel widget.

    package com.jtc.client;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.user.client.Window;
    import com.google.gwt.user.client.ui.Button;
    import com.google.gwt.user.client.ui.DecoratorPanel;
    import com.google.gwt.user.client.ui.HasHorizontalAlignment;
    import com.google.gwt.user.client.ui.Label;
    import com.google.gwt.user.client.ui.PopupPanel;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.VerticalPanel;
    public class HelloWorld implements EntryPoint {
    private static class MyPopup extends PopupPanel {
    public MyPopup() {
    // PopupPanel's constructor takes 'auto-hide' as its boolean
    // parameter. If this is set, the panel closes itself
    // automatically when the user clicks outside of it.
    super(true);
    // PopupPanel is a SimplePanel, so you have to set it's widget
    // property to whatever you want its contents to be.
    setWidget(new Label("Click outside of this popup to close it"));
    }
    }
    public void onModuleLoad() {
    Button b1 = new Button("Click me to show popup");
    b1.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
    // Instantiate the popup and show it.
    new MyPopup().show();
    }
    });
    Button b2 = new Button("Click me to show popup partway"
    +" across the screen");
    b2.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
    // Create the new popup.
    final MyPopup popup = new MyPopup();
    // Position the popup 1/3rd of the way down and across
    // the screen, and show the popup. Since the position
    // calculation is based on the offsetWidth and offsetHeight
    // of the popup, you have to use the
    // setPopupPositionAndShow(callback) method. The alternative
    // would be to call show(), calculate the left and
    // top positions, and call setPopupPosition(left, top).
    // This would have the ugly side effect of the popup jumping
    // from its original position to its new position.
    popup.setPopupPositionAndShow(new PopupPanel.PositionCallback(){
    public void setPosition(int offsetWidth, int offsetHeight) {
    int left = (Window.getClientWidth() - offsetWidth) / 3;
    int top = (Window.getClientHeight() - offsetHeight) / 3;
    popup.setPopupPosition(left, top);
    }
    });
    }
    });
    VerticalPanel panel = new VerticalPanel();
    panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    panel.setSpacing(10);
    panel.add(b1);
    panel.add(b2);
    DecoratorPanel decoratorPanel = new DecoratorPanel();
    decoratorPanel.add(panel);
    // Add the widgets to the root panel.
    RootPanel.get().add(decoratorPanel);
    }
    }

    Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:

    GWT - Dialog Box Widget

    Introduction

    The DialogBox widget represents a form of popup that has a caption area at the top and can be dragged by the user. Unlike a PopupPanel, calls to PopupPanel.setWidth(String) and PopupPanel.setHeight(String) will set the width and height of the dialog box itself, even if a widget has not been added as yet.

    Class Declaration

    Following is the declaration for com.google.gwt.user.client.ui.DialogBox class:

    public class DialogBox
    extends DecoratedPopupPanel
    implements HasHTML, HasSafeHtml, MouseListener

    Class Constructors
    S.N.Constructor & Description
    1DialogBox() Creates an empty dialog box.
    2DialogBox(boolean autoHide) Creates an empty dialog box, specifying its auto-hide property.
    3DialogBox(boolean autoHide, boolean modal) Creates an empty dialog box, specifying its auto-hide and modal properties.
    Class Methods
    S.N.Function name & Description
    1protected void beginDragging(MouseDownEvent event) Called on mouse down in the caption area, begins the dragging loop by turning on event capture.
    2protected void continueDragging(MouseMoveEvent event) Called on mouse move in the caption area, continues dragging if it was started by beginDragging(com.google.gwt.event.dom.client.MouseDownEvent).
    3protected void doAttachChildren() If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call Widget.on Attach() for each of its child widgets.
    4protected void doDetachChildren() If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call Widget.onDetach() for each of its child widgets.
    5protected void endDragging(MouseUpEvent event) Called on mouse up in the caption area, ends dragging by ending event capture.
    6DialogBox.Caption getCaption() Provides access to the dialog's caption.
    7java.lang.String getHTML() Gets this object's contents as HTML.
    8java.lang.String getText() Gets this object's text.
    9void hide() Hides the popup and detaches it from the page.
    10void onBrowserEvent(Event event) Fired whenever a browser event is received.
    11protected void onEnsureDebugId(java.lang.String baseID) Affected Elements: -caption = text at the top of the DialogBox. -content = the container around the content.
    12void on Mouse Down(Widget sender, int x, int y) Deprecated. Use begin Dragging (com.google.gwt.event.dom.client.Mouse Down Event) and get Caption() instead
    13void on Mouse Enter(Widget sender) Deprecated. Use Has Mouse Over Handlers. add Mouse Over Handler (com.google.gwt.event.dom.client.Mouse Over Handler) instead
    14void onMouseLeave(Widget sender) Deprecated. Use Has Mouse Out Handlers.add Mouse Out Handler (com.google.gwt.event.dom.client.Mouse Out Handler) instead
    15void onMouseMove(Widget sender, int x, int y) Deprecated. Use continueDragging(com.google.gwt.event.dom.client.MouseMoveEvent) and getCaption() instead
    16void onMouseUp(Widget sender, int x, int y) Deprecated. Use endDragging(com.google.gwt.event.dom.client.MouseUpEvent) and getCaption() instead
    17protected void onPreviewNativeEvent(Event.NativePreviewEvent event)
    18void setHTML(SafeHtml html) Sets the html string inside the caption.
    19void setHTML(java.lang.String html) Sets the html string inside the caption.
    20void setText(java.lang.String text) Sets the text inside the caption.
    21void show() Shows the popup and attach it to the page.
    Methods Inherited

    This class inherits methods from the following classes:
    • com.google.gwt.user.client.ui.UIObject
    • com.google.gwt.user.client.ui.Widget
    • com.google.gwt.user.client.ui.Panel
    • com.google.gwt.user.client.ui.SimplePanel
    • com.google.gwt.user.client.ui.PopupPanel
    • com.google.gwt.user.client.ui.DecoratedPopupPanel
    • java.lang.Object
    Dialogbox Widget Example

    This example will take you through simple steps to show usage of a DialogBox Widget in GWT. The following steps will help to you update the GWT application which we created in GWT - Create Application chapter:
    StepDescription
    1Create a project with a name HelloWorld under a package com.jtc as explained in the GWT - Create Application chapter.
    2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.javaas explained below. Keep rest of the files unchanged.
    3Compile and run the application to verify the result of the implemented logic.
    Following is the content of the modified module descriptor src/com.jtc/HelloWorld.gwt.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <module rename-to='helloworld'>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User'/>
    <!-- Inherit the default GWT style sheet. -->
    <inherits name='com.google.gwt.user.theme.clean.Clean'/>
    <!-- Specify the app entry point class. -->
    <entry-point class='com.jtc.client.HelloWorld'/>
    <!-- Specify the paths for translatable code -->
    <source path='client'/>
    <source path='shared'/>
    </module>

    Following is the content of the modified Style Sheet file war/HelloWorld.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;
    }
    .gwt-DialogBox .Caption {
    background: #e3e8f3 url(images/hborder.png) repeat-x 0px -2003px;
    padding: 4px 4px 4px 8px;
    cursor: default;
    border-bottom: 1px solid #bbbbbb;
    border-top: 5px solid #d0e4f6;
    }
    .gwt-DialogBox .dialogContent {
    }
    .gwt-DialogBox .dialogMiddleCenter {
    padding: 3px;
    background: white;
    }
    .gwt-DialogBox .dialogBottomCenter {
    background: url(images/hborder.png) repeat-x 0px -4px;
    -background: url(images/hborder_ie6.png) repeat-x 0px -4px;
    }
    .gwt-DialogBox .dialogMiddleLeft {
    background: url(images/vborder.png) repeat-y;
    }
    .gwt-DialogBox .dialogMiddleRight {
    background: url(images/vborder.png) repeat-y -4px 0px;
    -background: url(images/vborder_ie6.png) repeat-y -4px 0px;
    }
    .gwt-DialogBox .dialogTopLeftInner {
    width: 5px;
    zoom: 1;
    }
    .gwt-DialogBox .dialogTopRightInner {
    width: 8px;
    zoom: 1;
    }
    .gwt-DialogBox .dialogBottomLeftInner {
    width: 5px;
    height: 8px;
    zoom: 1;
    }
    .gwt-DialogBox .dialogBottomRightInner {
    width: 5px;
    height: 8px;
    zoom: 1;
    }
    .gwt-DialogBox .dialogTopLeft {
    background: url(images/corner.png) no-repeat -13px 0px;
    -background: url(images/corner_ie6.png) no-repeat -13px 0px;
    }
    .gwt-DialogBox .dialogTopRight {
    background: url(images/corner.png) no-repeat -18px 0px;
    -background: url(images/corner_ie6.png) no-repeat -18px 0px;
    }
    .gwt-DialogBox .dialogBottomLeft {
    background: url(images/corner.png) no-repeat 0px -15px;
    -background: url(images/corner_ie6.png) no-repeat 0px -15px;
    }
    .gwt-DialogBox .dialogBottomRight {
    background: url(images/corner.png) no-repeat -5px -15px;
    -background: url(images/corner_ie6.png) no-repeat -5px -15px;
    }
    html>body .gwt-DialogBox {
    }
    * html .gwt-DialogBox .dialogTopLeftInner {
    width: 5px;
    overflow: hidden;
    }
    * html .gwt-DialogBox .dialogTopRightInner {
    width: 8px;
    overflow: hidden;
    }
    * html .gwt-DialogBox .dialogBottomLeftInner {
    width: 5px;
    height: 8px;
    overflow: hidden;
    }
    * html .gwt-DialogBox .dialogBottomRightInner {
    width: 8px;
    height: 8px;
    overflow: hidden;
    }

    Following is the content of the modified HTML host file war/HelloWorld.html.

    <html>
    <head>
    <title>Hello World</title>
    <link rel="stylesheet" href="HelloWorld.css"/>
    <script language="javascript" src="helloworld/helloworld.nocache.js">
    </script>
    </head>
    <body>
    <h1>DialogBox Widget Demonstration</h1>
    <div id="gwtContainer"></div>
    </body>
    </html>

    Let us have following content of Java file src/com.jtc/HelloWorld.java which will demonstrate use of DialogBox widget.

    package com.jtc.client;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.user.client.Window;
    import com.google.gwt.user.client.ui.Button;
    import com.google.gwt.user.client.ui.DialogBox;
    import com.google.gwt.user.client.ui.HasHorizontalAlignment;
    import com.google.gwt.user.client.ui.Label;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.VerticalPanel;
    public class HelloWorld implements EntryPoint {
    private static class MyDialog extends DialogBox {
    public MyDialog() {
    // Set the dialog box's caption.
    setText("My First Dialog");
    // Enable animation.
    setAnimationEnabled(true);
    // Enable glass background.
    setGlassEnabled(true);
    // DialogBox is a SimplePanel, so you have to set its widget
    // property to whatever you want its contents to be.
    Button ok = new Button("OK");
    ok.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
    MyDialog.this.hide();
    }
    });
    Label label = new Label("This is a simple dialog box.");
    VerticalPanel panel = new VerticalPanel();
    panel.setHeight("100");
    panel.setWidth("300");
    panel.setSpacing(10);
    panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    panel.add(label);
    panel.add(ok);
    setWidget(panel);
    }
    }
    public void onModuleLoad() {
    Button b = new Button("Click me");
    b.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
    // Instantiate the dialog box and show it.
    MyDialog myDialog = new MyDialog();
    int left = Window.getClientWidth()/ 2;
    int top = Window.getClientHeight()/ 2;
    myDialog.setPopupPosition(left, top);
    myDialog.show();
    }
    });
    RootPanel.get().add(b);
    }
    }

    Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result:
    « Previous | 1 | 2 | 3 | Next »


  • copyright © 2014 - all rights riserved by javatechnologycenter.com