GWT – LAYOUT PANELSLayout 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.
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.
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
This class inherits methods from the following classes:
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:
This class inherits methods from the following classes:
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:
This class inherits methods from the following classes:
Following are few important Layout Panels:
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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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
This class inherits methods from the following classes:
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:
<?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: |