Table of contents
1.
Introduction🌼
2.
Class Declaration📜
3.
Nested Class Summary🧅
4.
Class Constructors and Description🗒️
5.
Class Methods and Description🗒️
6.
GWT HorizontalPanel Widget Methods Inherited⚓
7.
GWT HorizontalPanel Widget Example🗒️
7.1.
Frequently Asked Questions
7.2.
What is GWT?
7.3.
What is GWT Horizontal Panel Widget?
7.4.
What characteristics does GWT have?
7.5.
Who uses GWT - Google Web Toolkit?
7.6.
How advantageous is learning GWT?
8.
Conclusion
Last Updated: Mar 27, 2024
Easy

GWT Horizontal Panel Widget

Author Shiva
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction🌼

The Horizontal Panel in GWT represents a panel that lays all of its widgets out in a single Horizontal Column. This GWT Horizontal Panel Widget can be used to create complex layouts with a single horizontal column. Now let's see its class declaration along with other properties like class construction and methods.

introductory image

A panel with all of its widgets arranged in a single horizontal column.

Also see, procedure call in compiler design

Class Declaration📜

Declaration of com.google.gwt.user.client.ui.HorizontalPanel class −

public class HorizontalPanel 
extends CellPanel 
implements HasAlignment, InsertPanel.ForIsWidget

Nested Class Summary🧅

GWT Horizontal Panel Widget uses the different types of classes with specific purposes; some of the nested classes are defined below

  • Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject

UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled

  • Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasHorizontalAlignment

HasHorizontalAlignment.AutoHorizontalAlignmentConstant, HasHorizontalAlignment.HorizontalAlignmentConstant

  • Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasVerticalAlignment

HasVerticalAlignment.VerticalAlignmentConstant

  • Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.InsertPanel

InsertPanel.ForIsWidget

  • Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasWidgets

HasWidgets.ForIsWidget

Class Constructors and Description🗒️

GWT Horizontal Panel Widget constructors and their descriptions are listed below

Constructor 

Description

HorizontalPanel() It constructor for an empty horizontal panel.

Class Methods and Description🗒️

GWT Vertical Panel Widget methods and their descriptions are listed below

Sr.No.

Function name 

Description

1

void add(Widget w)

This method adds a child widget.

2

HasHorizontalAlignment.HorizontalAlignmentConstant getHorizontalAlignment()

This method get the horizontal alignment.

3

HasVerticalAlignment.VerticalAlignmentConstant getVerticalAlignment()

This method gets the vertical alignment.

4

void insert(IsWidget w, int beforeIndex)

This method inserts a widget based on the specified index provided as a parameter.

5

protected void onEnsureDebugId(java.lang.String baseID)

When the user uses the ensureDebugId(String) method to set the id, this method is called.

6

Boolean remove(Widget w)

This method Removes a child widget.

7

Void setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant align)

This property specifies the default horizontal alignment for widgets added to this panel.

8

Void setVerticalAlignment(HasVerticalAlignment.VerticalAlignmentConstant align)

This property specifies the default vertical alignment for widgets added to this panel.

GWT HorizontalPanel Widget Methods Inherited⚓

GWT vertical Panel Widget inherits the following methods

java.lang.Object
com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Panel
com.google.gwt.user.client.ui.ComplexPanel
com.google.gwt.user.client.ui.CellPanel
com.google.gwt.user.client.ui.HorizontalPanel

GWT HorizontalPanel Widget Example🗒️

In this example, we look for the usage of a Horizontal Panel Widget in GWT in simple steps. Now let's have a look at the step-wise construction of the GWT Horizontal Panel Widget.
 

Step 1: We’ll start off by creating a project with the name Horizontal Panel Widget under a package com.codingninjas.
 

Step 2: Then change the HorizontalPanelWidget.gwt.xml, HorizontalPanelWidget.css, HorizontalPanelWidget.html, and HorizontalPanelWidget.java as explained below. 
 

Step 3: Now, Compile and run the application to get the output
 

Here’s the content of the modified module descriptor src/com.codingninjas/HorizontalPanelWidget.gwt.xml.

<?xml version = "1.0" encoding = "UTF-8"?>
<module rename-to = 'HorizontalpanelWidget'>
<inherits name = 'com.google.gwt.user.User'/>
<inherits name = 'com.google.gwt.user.theme.clean.Clean'/>
<entry-point class = 'com.codingninjas.client.HorizontalpanelWidget'/>
<source path = 'client'/>
<source path = 'shared'/>
</module>

 

Content of the modified Style Sheet file war/HorizontalpanelWidget.css.

body {
  text-align: center;
}

h1 {
  font-size: 32px;
  font-weight: bold;
  color: #f79d00;
  text-align: center;
}

.gwt-CheckBox {
  margin: 10px;
}

 

Content of the modified HTML host file war/VerticalpanelWidget.html.

<html>
	<head>
	<title>HorizontalpanelWidget</title>
	<link rel="stylesheet" href="HorizontalWidget.css" />
	<script
		language="javascript"
		src="codingninjas/HorizontalpanelWidget.nocache.js"
	></script>
	</head>


	<body>
	<h1>GWT Horizontal Panel Widget Demonstration</h1>
	<div id="gwtContainer"></div>
	</body>
</html>

 

Let us have the following content of the Java file src/com.codingninjas/HorizontalpanelWidget.java, which will demonstrate the use of the HorizontalPanel widget.

package com.codingninjas.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 HorizontalpanelWidget implements EntryPoint {


   public void onModuleLoad() {
       HorizontalPanel horizontalPanel = new HorizontalPanel();
         for(int i = 1;  i <= 5; i++){
         CheckBox checkBox = new CheckBox("Element " + i);
         horizontalPanel.add(checkBox);
      }
      DecoratorPanel decoratorPanel = new DecoratorPanel();
      decoratorPanel.add(horizontalPanel);


      /* Add the widgets to the root panel. */ 
      RootPanel.get().add(decoratorPanel);
   }
}

 

Output:

output image

 

Frequently Asked Questions

What is GWT?

GWT (Google web toolkit) is an open-source development toolkit provided by google for developing browser-based, complex Ajax applications. We can even develop Rich Internet Applications (RIA) in Java using GWT, which will then be compiled into Javascript and cross-browser compliant.

What is GWT Horizontal Panel Widget?

The HorizontalPanel widget represents a panel that lays all of its widgets out in a single Horizontal Column. This lays all of its widgets out in a single horizontal column. 

What characteristics does GWT have?

Asynchronous remote procedure calls, history management, bookmarking, UI abstraction, internationalization, and cross-browser portability.

Who uses GWT - Google Web Toolkit?

Companies like Crimsonlogic Pte. Ltd., StudyBlue Inc., and Intrado Inc. are using GWT.

How advantageous is learning GWT?

Many Google projects, both internal and external, are based on GWT; therefore Google will need to sustain the technology as long as they need to keep improving the front-end.

Conclusion

In this article, we have extensively discussed how the project GWT Horizontal Panel Widget. We have discussed its constructors, methods, and implementation. GWT Horizontal Panel Widget is a part of form widgets that are used in many places while developing applications. and if you would like to learn more, check out our articles on

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. 

Enroll in our courses and refer to the mock test and problems available.

Take a look at the interview experiences and interview bundle for placement preparations.

Live masterclass