GWT - DockPanel Widget



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 class:

public class DockPanel
   extends CellPanel
      implements HasAlignment

Class constructors

S.N.Constructor & Description
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 setCellHorizontalAlignment(Widget w, HasHorizontalAlignment.HorizontalAlignmentConstant align)
Deprecated. Sets the horizontal alignment of the given widget within its cell.
9void setCellVerticalAlignment(Widget w, HasVerticalAlignment.VerticalAlignmentConstant 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 setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant 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:






  • java.lang.Object

DockPanel Widget Example

This example will take you through simple steps to show usage of a DockPanel Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter:

1Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter.
2Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and as 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.tutorialspoint/HelloWorld.gwt.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
  <!-- Inherit the core Web Toolkit stuff.                        -->
  <inherits name=''/>

  <!-- Inherit the default GWT style sheet.                       -->
  <inherits name=''/>

  <!-- Specify the app entry point class.                         -->
  <entry-point class='com.tutorialspoint.client.HelloWorld'/>

  <!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>


Following is the content of the modified Style Sheet file war/HelloWorld.css.

   text-align: center;
   font-family: verdana, sans-serif;
   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.

<title>Hello World</title>
   <link rel="stylesheet" href="HelloWorld.css"/>
   <script language="javascript" src="helloworld/helloworld.nocache.js">

<h1>DockPanel Widget Demonstration</h1>
<div id="gwtContainer"></div>


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

package com.tutorialspoint.client;


public class HelloWorld implements EntryPoint {

   public void onModuleLoad() {
      DockPanel dockPanel = new DockPanel();

      // Add text all around
      dockPanel.add(new HTML("This is the first north component."), 
      dockPanel.add(new HTML("This is the first south component."), 
      dockPanel.add(new HTML("This is the east component."), 
      dockPanel.add(new HTML("This is the west component."), 
      dockPanel.add(new HTML("This is the second north component."), 
      dockPanel.add(new HTML("This is the second south component"), 

      // 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();

      // Add the widgets to the root 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 DockPanel Widget