Package com.vaadin.ui

Interface Component.Focusable

    • Method Detail

      • focus

        void focus()
        Sets the focus to this component.
         Form loginBox = new Form();
         loginBox.setCaption("Login");
         layout.addComponent(loginBox);
        
         // Create the first field which will be focused
         TextField username = new TextField("User name");
         loginBox.addField("username", username);
        
         // Set focus to the user name
         username.focus();
        
         TextField password = new TextField("Password");
         loginBox.addField("password", password);
        
         Button login = new Button("Login");
         loginBox.getFooter().addComponent(login);
         

        Notice that this interface does not provide an accessor that would allow finding out the currently focused component. Focus information can be acquired for some (but not all) Field components through the FieldEvents.FocusListener and FieldEvents.BlurListener interfaces.

        See Also:
        FieldEvents, FieldEvents.FocusEvent, FieldEvents.FocusListener, FieldEvents.BlurEvent, FieldEvents.BlurListener
      • getTabIndex

        int getTabIndex()
        Gets the tabulator index of the Focusable component.
        Returns:
        tab index set for the Focusable component
        See Also:
        setTabIndex(int)
      • setTabIndex

        void setTabIndex​(int tabIndex)
        Sets the tabulator index of the Focusable component. The tab index property is used to specify the order in which the fields are focused when the user presses the Tab key. Components with a defined tab index are focused sequentially first, and then the components with no tab index.
         Form loginBox = new Form();
         loginBox.setCaption("Login");
         layout.addComponent(loginBox);
        
         // Create the first field which will be focused
         TextField username = new TextField("User name");
         loginBox.addField("username", username);
        
         // Set focus to the user name
         username.focus();
        
         TextField password = new TextField("Password");
         loginBox.addField("password", password);
        
         Button login = new Button("Login");
         loginBox.getFooter().addComponent(login);
        
         // An additional component which natural focus order would
         // be after the button.
         CheckBox remember = new CheckBox("Remember me");
         loginBox.getFooter().addComponent(remember);
        
         username.setTabIndex(1);
         password.setTabIndex(2);
         remember.setTabIndex(3); // Different than natural place
         login.setTabIndex(4);
         

        After all focusable user interface components are done, the browser can begin again from the component with the smallest tab index, or it can take the focus out of the page, for example, to the location bar.

        If the tab index is not set (is set to zero), the default tab order is used. The order is somewhat browser-dependent, but generally follows the HTML structure of the page.

        A negative value means that the component is completely removed from the tabulation order and can not be reached by pressing the Tab key at all.

        Parameters:
        tabIndex - the tab order of this component. Indexes usually start from 1. Zero means that default tab order should be used. A negative value means that the field should not be included in the tabbing sequence.
        See Also:
        getTabIndex()