Home Tutorials Swt Creating Composite Widgets using GWT

Related Tutorials


Share on Google+Share on Google+

Creating Composite Widgets using GWT

Creating Composite Widgets using GWT

Creating Composite Widgets using GWT


This example describes the Basics for creating composite widgets using GWT. The steps involved in Building the Composite widgets are described below:-

final Label label = new Label("Click the Node to view Tree structure")
Here we are declaring label. Label is a widget that contains text.

private TextBox tb = new TextBox();
Declaring a new TextBox as tb.

private CheckBox cb = new CheckBox();
Declaring a new CheckBox as cb.

VerticalPanel panel = new VerticalPanel()
Creating a Vertical panel named as panel.

This is the method of the panel class for adding checkbox to the panel.

By this method we are adding label to the rootpanel.Root panel is a panel to which all other widgets must  be added. it is not created directly.


package org.yournamehere.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class Compositewidgetex implements EntryPoint{
private static class OptionalTextBox extends Composite 
implements ClickListener {
   private TextBox tb = new TextBox();
  private CheckBox cb = new CheckBox();

  public OptionalTextBox(String caption) {

  VerticalPanel panel = new VerticalPanel();


  public void onClick(Widget sender) {
  if (sender == cb) {
  public void setCaption(String caption) {
  public String getCaption() {
  return cb.getText();

  public void onModuleLoad() {
 final Label label = new
Label("Example to show Composite widgets");
  final Label label1 = new 
Label("   ");
  OptionalTextBox optionalTextBox = 
new OptionalTextBox("Check this to enable");


<?xml version="1.0" encoding="UTF-8"?>
  <inherits name="com.google.gwt.user.User"/>

Output of the program :


Download sourcecode



If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Discuss: Creating Composite Widgets using GWT  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image