More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

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.

panel.add(cb)
This is the method of the panel class for adding checkbox to the panel.

RootPanel.get().add(label1)
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.

Compositewidgetex.java

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();
      panel.add(cb);
      panel.add(tb);

      cb.setText(caption);
      cb.setChecked(true);
      cb.addClickListener(this);
      initWidget(panel);
          }

    public void onClick(Widget sender) {
      if (sender == cb) {
        tb.setEnabled(cb.isChecked());
      }
    }
    public void setCaption(String caption) {
      cb.setText(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");
    RootPanel.get().add(label);
        RootPanel.get().add(label1);
    RootPanel.get().add(optionalTextBox);
    
  }
}

Main.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module>
  <inherits name="com.google.gwt.user.User"/>
  <entry-point class="org.yournamehere.client.Compositewidgetex"/>
  
</module>

Output of the program :

       

Download sourcecode

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Join and Excel yourself with our Online instructor led training sessions
Training Courses
Tell A Friend
Your Friend Name

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.