Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Class Declaration
3.
Class Constructors
4.
Class Methods
5.
Inherited Methods
6.
Frequently Asked Questions
6.1.
Why use GWT?
6.2.
What is the GWT's purpose?
6.3.
What is a GWT client?
6.4.
What is GWT coding?
6.5.
What benefits does GWT offer?
7.
Conclusion
Last Updated: Mar 27, 2024

GWT ScrollPanel Widget

Author soham Medewar
0 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Google Web Toolkit, sometimes known as GWT Web Toolkit, is an open-source suite of tools that allows web developers to design and maintain JavaScript front-end applications with the help of Java.

GWT image

GWT ScrollPanel encloses the content in a scrollable zone. Using ScrollPanel constructors, we can create various types of scroll panels. This class is part of the package com.google.gwt.user.client.ui.ScrollPanel.

Class Declaration

The declaration for com.google.gwt.user.client.ui.ScrollPanel is shown below.

public class ScrollPanel
  extends SimplePanel
      implements ProvidesResize, SourcesScrollEvents, RequiresResize, HasScrollHandlers
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Class Constructors

Sr. No. Constructor  Description
1. ScrollPanel() This constructor helps us to create an empty scroll panel.
2. ScrollPanel(Widget child) This constructor helps us to create a new scroll panel with the given child widget.
3. ScrollPanel(Element root, Element scrollable, Element container) Creates an empty scroll panel using the root, scrollable, and container components supplied.

Class Methods

Sr. No. Function Description
1. addScrollHandler Usage: public HandlerRegistration addScrollHandler(ScrollHandler handler)
This method helps us to add a scroll handler. It accepts the parameter ScrollHandler, and it returns the HandlerRegistration to remove this handler.
2. addScrollListener Usage: public void addScrollListener(ScrollListener listener)
This method adds a listener interface to receive scroll events in the Scroll Panel. It accepts the ScrollListnet parameter that the listener interface to add inside the Scroll Panel.
3. ensureVisible Usage: public void ensureVisible(UIObject item)
By altering the panel's scroll position, this technique guarantees that the provided item is displayed. It accepts the UIObject as a parameter whose visibility is to be ensured.
4.  getHorizontalScrollPosition Usage: public int getHorizontalScrollPosition()
The horizontal scroll position of the Scroll Panel is obtained using this approach. It returns the horizontal scroll position of the panel in pixels.
5.  getMaximumHorizontalScrollPosition Usage: public int getMaximumHorizontalScrollPosition()
This function returns the maximum horizontal scrolling position (usually scroll width - client width).
6.  getMaximumVerticalScrollPosition Usage: public int getMaximumVerticalScrollPosition()
This function returns the maximum vertical scrolling position (usually scroll height - client height).
7.  getMinimumHorizontalScrollPosition Usage: public int getMinimumHorizontalScrollPosition()
This function returns the minimum horizontal scrolling position.
8.  getMinimumVerticalScrollPosition Usage: public int getMinimumVerticalScrollPosition()
This function returns the minimum vertical scrolling position
9.  getScrollPosition Usage: public int getScrollPosition()
This method returns the vertical scroll position of the Scroll Panel in pixels(int value).
10. getVerticalScrollPosition Usage: public int getVerticalScrollPosition()
This method returns the vertical scroll position of the Scroll Panel in pixels(int value).
11.  isTouchScrollingDisabled Usage: public boolean isTouchScrollingDisabled()
This method determines whether touch-based scrolling is enabled or disabled. On devices that do not allow touch scrolling, this function always returns false.
12.  onResize Usage: public void onResize()
This method must be invoked anytime the size of the implementor is changed.
13. removeScrollListener Usage: public void removeScrollListener(ScrollListener listener)
This method helps us to remove the previously added scroll listener.
14. scrollToBottom Usage: public void scrollToBottom()
This method helps us to go to the bottom of the Scroll Panel.
15. scrollToLeft Usage: public void scrollToLeft()
This method helps us to reach the far left of this Scroll Panel.
16. scrollToRight Usage: public void scrollToRight()
This method helps us to reach the far right of this Scroll Panel.
17. scrollToTop Usage: public void scrollToTop()
This method helps us to go to the top of the Scroll Panel.
18. setAlwaysShowScrollBars Usage: public void setAlwaysShowScrollBars(boolean alwaysShow)
Sets whether the scroll bars in this panel are always shown or just when needed. To display the Scroll Bar always, set the alwaysShow parameter to true.
19. setHeight Usage: public void setHeight(java.lang.String height)
This method assists us in setting the height of the item. This height excludes any embellishments such as a border, margin, or padding. The height parameter must be passed into the function as absolute CSS units, i.e., “10px”, “10rem”, etc.
20. setHorizontalScrollPosition Usage: public void setHorizontalScrollPosition(int position)
This method helps us to set the horizontal scroll position. The parameter position passed into the function is the new position of the horizontal scroll in pixels.
21. setScrollPosition Usage: public void setScrollPosition(int position)
This method helps us to set the vertical scroll position. The parameter position passed into the function is the new position of the horizontal scroll in pixels.
22. setSize Usage: public void setSize(java.lang.String width, java.lang.String height)
This method assists us in setting the size of the item. This size does not contain any decorative elements such as a border, margin, or padding. The setSize method accepts two parameters, i.e., width and height of the item. All the parameters must be passed into the function as absolute CSS units, i.e., “10px”, “10rem”, etc.
23. setTouchScrollingDisabled Usage: public boolean setTouchScrollingDisabled(boolean isDisabled)
This method controls whether touch scrolling is enabled or deactivated. Touch scrolling is enabled by default on devices that handle touch events. It returns true if touch scrolling is enabled and supported; false otherwise.
24. setVerticalScrollPosition Usage: public void setVerticalScrollPosition(int position)
This method helps us to set the vertical scroll position. It takes an int as a parameter, i.e., the position of the vertical scroll in pixels.
25. setWidth Usage: public void setWidth(java.lang.String width)
This method determines the width of the object. This width excludes any decorations such as a border, margin, or padding. The width parameter must be passed into the function as absolute CSS units, i.e., “10px”, “10rem”, etc.
26. getContainerElement Usage: protected Element getContainerElement()
Override this function to indicate that the container for the panel's child widget be an element other than the root element. This is handy for creating a basic panel that decorates its contents. To ensure backward compatibility, this function continues to return the Element class described in the User module.
27. getScrollableElement Usage: protected Element getScrollableElement()
This method is used to get the scrollable element. That is the element with the overflow property set to 'auto' or 'scroll.'

Inherited Methods

The methods of this class are inherited from the following classes:

  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.SimplePanel
  • com.google.gwt.user.client.ui.Panel
  • java.lang.Object

Frequently Asked Questions

Why use GWT?

If you are a seasoned Java programmer with knowledge of Swing or AWT, selecting GWT should be simple. With this foundation, the learning curve is the shortest. Even if you lack experience in Java GUI programming, the years spent working on server-side Java will be helpful when creating GWT applications.

What is the GWT's purpose?

A GWT development toolkit is used to create and improve sophisticated browser-based apps. GWT's objective is to make it possible to construct high-performance web apps productively without the developer having to be an expert in JavaScript, XMLHttpRequest, or browser quirks.

What is a GWT client?

A variety of HTTP client classes in GWT make it easier to send personalized HTTP requests to your server and, optionally, handle responses that are structured in JSON or XML. Your application may send general HTTP requests thanks to GWT's collection of HTTP client classes.

What is GWT coding?

An open-source Java software development platform called Google Web Toolkit (GWT) makes it simple to create AJAX apps. You may use the Java development tools of your choice to create and debug AJAX apps with GWT.

What benefits does GWT offer?

If we are experienced Java programmers with knowledge of Swing or AWT, selecting GWT should be simple. With this foundation, the learning curve is the shortest. Even if you lack experience in Java GUI development, the years spent working on server-side Java will be helpful when creating GWT applications.

Conclusion

In this article, we have learned about the GWT Scroll Panel widget and its methods.

If you want to learn more, check out our articles on GWT UI BinderGWT DeckPanel WidgetGWT TabPanel Widget, and GWT Composite Widget.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning, Ninjas!

thank you image
Previous article
GWT SimplePanel Widget
Next article
GWT FocusPanel
Live masterclass