Table of contents
1.
Introduction
2.
Class Declaration
3.
Class Constructors
4.
Class Methods
5.
Methods Inherited
6.
Frequently Asked Questions
6.1.
In GWT, how can I set the focus?
6.2.
What is the GWT widget?
6.3.
What does the GWT flow panel do?
6.4.
What is a layout widget?
6.5.
Are widgets with states unchangeable?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

GWT FocusPanel

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

Introduction

The FocusPanel widget is a straightforward panel with the ability to focus its contents and add mouse and keyboard event catching.

gwt

Let's dive deeper into the GWT FocusPanel. So without any further ado, let's get started!

Class Declaration

The declaration for the class com.google.gwt.user.client.ui.FocusPanel is provided below:

public class FocusPanel
   extends SimplePanel
      implements HasFocus, SourcesClickEvents, 
         SourcesMouseEvents, SourcesMouseWheelEvents, 
            HasAllMouseHandlers, HasClickHandlers, 
               HasDoubleClickHandlers, HasAllKeyHandlers,
                  HasAllFocusHandler

Class Constructors

Sr. No. Constructor  Description
1. FocusPanel() Creates an empty focus panel.
2. FocusPanel(Widget child) A new focus panel is created with the specified child widget.

Class Methods

Sr. No. Methods Description
1. HandlerRegistration addBlurHandler(BlurHandler handler)

Adds a handler for a BlurEvent. The blur handler is one of the parameters.

Returns: The HandlerRegistration code needed to delete this handler

2. HandlerRegistration addClickHandler(ClickHandler handler)

A click event handler is added. The click handler is one of the parameters.

Returns: The HandlerRegistration code is needed to delete this handler.

3. public void addClickListener(ClickListener listener)

Includes an interface for listeners to receive click events.

parameters: listener - the interface for adding listeners.

4.  public HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler)

A DoubleClickEvent handler is added. The double click handler for the handler is one of its parameters.

Returns: The HandlerRegistration code is needed to delete this handler.

5.  public HandlerRegistration addDragEndHandler(DragEndHandler handler)

A DragEndEvent handler is added. The drag end handler is one of the parameters.

Returns: The HandlerRegistration code is needed to delete this handler.

6.  public HandlerRegistration addDragEnterHandler(DragEnterHandler handler)

a DragEnterEvent handler is added. The drag end handler is one of the parameters.

Returns: The HandlerRegistration code is needed to delete this handler.

7.  public HandlerRegistration addDragHandler(DragHandler handler)

A DragEvent handler is added. Drag handler is one of the parameters.

Returns: The HandlerRegistration code is needed to delete this handler.

8.  public HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler)

A DragLeaveEvent handler is added. The drag leave handler is one of the parameters.

Returns: The HandlerRegistration code is needed to delete this handler.

9.  public HandlerRegistration addDragOverHandler(DragOverHandler handler)

A DragOverEvent handler is added. The dragover handler is its parameters.

Returns: The HandlerRegistration code is needed to delete this handler.

10. public HandlerRegistration addDragStartHandler(DragStartHandler handler)

A DragStartEvent handler is added. The drag start handler is one of the parameters.

Returns: The HandlerRegistration code needed to delete this handler

11.  addDropHandler public HandlerRegistration (DropHandler handler)

Adds a handler for the drop event.The drop handler is its only parameter.

Returns: This handler was deleted using HandlerRegistration.

12.  public HandlerRegistration addFocusHandler(FocusHandler handler)

Adds a handler for a FocusEvent. The focus handler is one of the parameters.

Returns: The HandlerRegistration code is needed to delete this handler.

13. public void addFocusListener(FocusListener listener)

provide an interface for listeners to receive focus events.

Parameters: The lFocusistener listener.

14. public HandlerRegistration addGestureChangeHandler(GestureChangeHandler handler)

Adds a handler for the GestureChangeEvent. The GestureChangeHandler handler is its parameter.

Returns: The HandlerRegistration code needed to delete this handler

15. public HandlerRegistration addGestureEndHandler(GestureEndHandler handler)

GestureEndEvent handler is added.

parameters: the gesture end handler and handler

Returns: The HandlerRegistration code needed to delete this handler

16. public HandlerRegistration addGestureStartHandler(GestureStartHandler handler)

GestureStartEvent handler is added. The gesture start handler is one of the parameters.

Returns: The HandlerRegistration code needed to delete this handler

17. public void addKeyboardListener(KeyboardListener listener)

Adds an interface for a listener to take keyboard events.

Parameters: The KeyboardListener listener.

18. public HandlerRegistration addKeyDownHandler(KeyDownHandler handler)

adds a handler for the KeyDownEvent.

Parameters: The key-down handler.

Returns: This handler was deleted using HandlerRegistration.

19. public HandlerRegistration addKeyPressHandler(KeyPressHandler handler)

a KeyPressEvent handler is added. Keypress handler (handler) is one of the parameters.

Returns: The HandlerRegistration code needed to delete this handler

20. public HandlerRegistration addKeyUpHandler(KeyUpHandler handler)

A KeyUpEvent handler is added.

Parameters: the keyUp, handler handler

Returns: The HandlerRegistration code needed to delete this handler

21. public HandlerRegistration addMouseDownHandler(MouseDownHandler handler)

A MouseDownEvent handler is added. The down-mouse handler is one of the parameters.

Returns: The HandlerRegistration code needed to delete this handler

22. public void addMouseListener(MouseListener listener)

includes an interface for a listener to receive mouse events.

parameters: listener - the interface for adding listeners

23. public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler)

adds a handler for the MouseMoveEvent. handler - the handler for the mouse movement

Returns: The HandlerRegistration code is needed to delete this handler.

24. public AddMouseOutHandlerHandlerRegistration (MouseOutHandler handler)

A MouseOutEvent handler is added. The mouse-out handler is one of the parameters.

Returns: The HandlerRegistration code needed to delete this handler

25. public HandlerRegistration addMouseUpHandler(MouseUpHandler handler)

A MouseUpEvent handler is added. The mouse should be raised as a parameter. handler

Returns: The HandlerRegistration code is needed to delete this handler.

26. public HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler)

Adds a handler for the MouseWheelEvent. The mouse wheel handler is one of the parameters.

Returns: The HandlerRegistration code needed to delete this handler

27. public void addMouseWheelListener(MouseWheelListener listener)

Includes an interface for a listener to receive mouse events.

parameters: The MouseWheelListener.

28. public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler)

A TouchCancelEvent handler is added. The touch cancel handler is one of the parameters.

Returns: The HandlerRegistration code needed to delete this handler

29. public HandlerRegistration addTouchEndHandler(TouchEndHandler handler)

A TouchEndEvent handler is added. The touch end handler is one of the parameters.

Returns: The HandlerRegistration code needed to delete this handler

30. public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler)

A TouchMoveEvent handler is added. The touch move handler is one of the parameters

Returns: The HandlerRegistration code needed to delete this handler

31. public HandlerRegistration addTouchStartHandler(TouchStartHandler handler)

A TouchStartEvent handler is added. The touch start handler is one of the parameters.

Returns: The HandlerRegistration code needed to delete this handler

32. public int getTabIndex() Provides the widget's tab index back.
33. public void removeClickListener(ClickListener listener) Removes a listener interface that has already been added. Specifies the listener interface to be removed.
34. public void removeFocusListener(FocusListener listener)

Deletes a listener interface that was previously added.

parameters: The FocusListener listener.

35. public void removeKeyboardListener(KeyboardListener listener) removes a listener interface that has already been added. Specifies the listener interface to be removed.
36. public void removeMouseListener(MouseListener listener)

Deletes a listener interface that was previously added.

parameters: The MouseListener listener.

37. public void removeMouseWheelListener(MouseWheelListener listener)

the elimination of a previously added listener interface.

parameters: The MouseWheelListener listener.

38. public void setAccessKey(char key)

the access key for the widget is set. To automatically focus the widget, press this key in combination with a modifier key that is specific to your browser.

Parameters:char  key - the access key for the widget

39. public void setFocus(boolean focused) Focus or defocus this widget. At any given time, only one widget can be the focus, and that widget will receive all keyboard events. FocusEvents are typically fired asynchronously by browsers. It would help if you made your test asynchronous to verify, especially in GWT tests, properly. For instructions on how to achieve this, refer to GWTTestCase#delayTestFinish. Focused determines whether or not this widget should take attention.
40. public void setTabIndex(int index) Positions the widget in the tab index. When multiple widgets share the same tab index, they will all gain focus randomly. This widget will be removed from the tab order if the tab index is set to -1. The widget's tab index is one of the parameters.

Methods Inherited

This class inherits methods from the following classes −

  • 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.SimplePanel
  • java.lang.Object

Frequently Asked Questions

In GWT, how can I set the focus?

Create a property field for your TextBox, then call textBox from your setFocus method. Regardless of what you gave your TextBox property's name, setFocus(true).

What is the GWT widget?

In GWT applications, widgets included in panels are used to build user interfaces. Use widgets to communicate with users. The positioning of user interface elements on the page is managed via panels.

What does the GWT flow panel do?

GWT The simplest panel is FlowPanel, which uses the standard HTML layout to modify the format of child widgets. HTML element, or an HTML div, ties itself to children immediately. Thus no adjustment is necessary for the Flow Panel.

What is a layout widget?

The widget is the layout mechanism's central idea. Flutter is known to treat everything as a widget. Therefore, your app's image, icon, text, and even layout are all widgets.

Are widgets with states unchangeable?

Because StatefulWidget instances are immutable, their mutable state is either saved in separate State objects made by the createState method or in objects to which the StatefulWidget subscribes, such as Stream or ChangeNotifier objects, to which references are kept in final fields.

Conclusion

In this article, we learned about different types of constructors used, different types of methods used, and types of methods inherited. 

If you want to learn more, check out our articles on GWT UI BinderGWT Event HandlingGWT 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
Live masterclass