Results 1 to 1 of 1
  1. #1
    Java Example is offline Moderator
    Join Date
    Sep 2014
    Posts
    27
    Rep Power
    0

    Default How to create composite widgets using GWT?

    In this tutorial, we will illustrate how to build composite widget using GWT. The steps involved in Building the Composite widgets are described below:-

    First we need to declare label,TextBox,CheckBox,VerticalPanle as shown below:


    Java Code: Code to declare the components
    final Label label = new Label("Click the Node to view Tree structure")
    private TextBox tb = new TextBox();
    private CheckBox cb = new CheckBox();
    VerticalPanel panel = new VerticalPanel()
    We can add the checkbox to the panel using the panel.add(cb) method.The RootPanel.get().add(label1) method is used to add label to the rootpanel. Root panel is a panel to which all other widgets must be added. It is not created directly.

    Java Code: Code to create a Composite widget using GWT
    package org.widget.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.widget.client.Compositewidgetex"/>
      
    </module>
    Output of the program

    How to create composite widgets using GWT?-2.jpg

    How to create composite widgets using GWT?-2a.jpg
    Last edited by Java Example; 09-27-2014 at 08:47 PM.

Similar Threads

  1. Custom alignment of SWT widgets inside Composite
    By venkat.eclipse in forum SWT / JFace
    Replies: 2
    Last Post: 02-16-2011, 08:49 PM
  2. getting problem in disposing the widgets
    By thendral m in forum SWT / JFace
    Replies: 7
    Last Post: 01-12-2010, 08:37 AM
  3. How to create widgets on some event
    By sarbuland in forum Advanced Java
    Replies: 0
    Last Post: 02-06-2008, 08:08 PM
  4. How to create widgets dynamically
    By sarbuland in forum Advanced Java
    Replies: 0
    Last Post: 02-06-2008, 08:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •