GWT - Widget FocusPanel

Introdução

o FocusPanel widget representa um painel simples que torna seu conteúdo focalizável e adiciona a capacidade de capturar eventos de mouse e teclado.

Declaração de Classe

A seguir está a declaração para com.google.gwt.user.client.ui.FocusPanel classe -

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

Construtores de classe

Sr. Não. Construtor e descrição
1

FocusPanel()

Cria um painel de foco vazio.

2

FocusPanel(Widget child)

Cria um novo painel de foco com o widget filho fornecido.

Métodos de aula

Sr. Não. Nome e descrição da função
1

HandlerRegistration addBlurHandler(BlurHandler handler)

Adiciona um manipulador BlurEvent.

2

HandlerRegistration addClickHandler(ClickHandler handler)

Adiciona um manipulador ClickEvent.

3

void addClickListener(ClickListener listener)

Descontinuada. Use addClickHandler (com.google.gwt.event.dom.client.ClickHandler) em vez disso

4

HandlerRegistration addDoubleClickHandler (DoubleClickHandler handler)

Adiciona um manipulador DoubleClickEvent.

5

HandlerRegistration addFocusHandler(FocusHandler handler)

Adiciona um manipulador FocusEvent.

6

void addFocusListener (FocusListener listener)

Descontinuada. Use addFocusHandler (com.google.gwt.event.dom.client.FocusHandler) em vez disso

7

void addKeyboardListener (KeyboardListener listener)

Descontinuada. Use addKeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler), addKeyUpHandler (com.google.gwt.event.dom.client.KeyUpHandler) e addKeyPressHandler (com.google.gwt.event.dom.client.KeyPressHandler ) em vez de

8

HandlerRegistration addKeyDownHandler (KeyDownHandler handler)

Adiciona um manipulador KeyDownEvent.

9

HandlerRegistration addKeyPressHandler (KeyPressHandler handler)

Adiciona um manipulador KeyPressEvent.

10

HandlerRegistration addKeyUpHandler (KeyUpHandler handler)

Adiciona um manipulador KeyUpEvent.

11

HandlerRegistration addMouseDownHandler (MouseDownHandler handler)

Adiciona um manipulador MouseDownEvent.

12

void addMouseListener(MouseListener listener)

Descontinuada. Use addMouseOverHandler (com.google.gwt.event.dom.client.MouseOverHandler), addMouseMoveHandler (com.google.gwt.event.dom.client.MouseMoveHandler), addMouseDownHandler (com.google.gwt.event.dom.client.MouseDownHandler ), addMouseUpHandler (com.google.gwt.event.dom.client.MouseUpHandler) e addMouseOutHandler (com.google.gwt.event.dom.client.MouseOutHandler) em vez disso

13

HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler)

Adiciona um manipulador MouseMoveEvent.

14

HandlerRegistration addMouseOutHandler(MouseOutHandler handler)

Adiciona um manipulador MouseOutEvent.

15

HandlerRegistration addMouseOverHandler(MouseOverHandler handler)

Adiciona um manipulador MouseOverEvent.

16

HandlerRegistration addMouseUpHandler(MouseUpHandler handler)

Adiciona um manipulador MouseUpEvent.

17

HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler)

Adiciona um manipulador MouseWheelEvent.

18

void addMouseWheelListener(MouseWheelListener listener)

Descontinuada. Use addMouseWheelHandler (com.google.gwt.event.dom.client.MouseWheelHandler) em vez disso

19

int getTabIndex()

Obtém a posição do widget no índice da guia.

20

void removeClickListener(ClickListener listener)

Descontinuada. Use o método HandlerRegistration.removeHandler () no objeto retornado por addClickHandler (com.google.gwt.event.dom.client.ClickHandler) em vez disso

21

void removeFocusListener(FocusListener listener)

Descontinuada. Use o método HandlerRegistration.removeHandler () no objeto retornado por addFocusHandler (com.google.gwt.event.dom.client.FocusHandler) em vez disso

22

void removeKeyboardListener(KeyboardListener listener)

Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by an add*Handler method instead

23

void removeMouseListener(MouseListener listener)

Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by an add*Handler method instead

24

void removeMouseWheelListener(MouseWheelListener listener)

Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addMouseWheelHandler (com.google.gwt.event.dom.client.MouseWheelHandler) instead

25

void setAccessKey(char key)

Sets the widget's 'access key'.

26

void setFocus(boolean focused)

Explicitly focus/unfocus this widget.

27

void setTabIndex(int index)

Sets the widget's position in the tab index.

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

FocusPanel Widget Example

This example will take you through simple steps to show usage of a FocusPanel Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter −

Step Description
1 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter.
2 Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged.
3 Compile and run the application to verify the result of the implemented logic.

Following is the content of the modified module descriptor src/com.tutorialspoint/HelloWorld.gwt.xml.

<?xml version = "1.0" encoding = "UTF-8"?>
<module rename-to = 'helloworld'>
   <!-- Inherit the core Web Toolkit stuff.                        -->
   <inherits name = 'com.google.gwt.user.User'/>

   <!-- Inherit the default GWT style sheet.                       -->
   <inherits name = 'com.google.gwt.user.theme.clean.Clean'/>

   <!-- Specify the app entry point class.                         -->
   <entry-point class = 'com.tutorialspoint.client.HelloWorld'/>

   <!-- Specify the paths for translatable code                    -->
   <source path= 'client'/>
   <source path = 'shared'/>

</module>

Following is the content of the modified Style Sheet file war/HelloWorld.css.

body {
   text-align: center;
   font-family: verdana, sans-serif;
}

h1 {
   font-size: 2em;
   font-weight: bold;
   color: #777777;
   margin: 40px 0px 70px;
   text-align: center;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
   <head>
      <title>Hello World</title>
      <link rel = "stylesheet" href = "HelloWorld.css"/>
      <script language = "javascript" src = "helloworld/helloworld.nocache.js">
      </script>
   </head>

   <body>
      <h1>FocusPanel Widget Demonstration</h1>
      <div id = "gwtContainer"></div>
   </body>
</html>

Let us have following content of Java file src/com.tutorialspoint/HelloWorld.java which will demonstrate use of FocusPanel widget.

package com.tutorialspoint.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;

public class HelloWorld implements EntryPoint {

   public void onModuleLoad() {
      // Create text 
      HTML contents = new HTML("This is a FocusPanel."
         +" Click on the panel and it will attain focus.");

      //create focus panel with content
      FocusPanel focusPanel = new FocusPanel(contents);
      focusPanel.setSize("400px", "100px");

      DecoratorPanel decoratorPanel = new DecoratorPanel();

      decoratorPanel.add(focusPanel);

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

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result −