Class TextBox

All Implemented Interfaces:
IsEditor<ValueBoxEditor<String>>, HasAllDragAndDropHandlers, HasAllFocusHandlers, HasAllGestureHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasAllTouchHandlers, HasBlurHandlers, HasChangeHandlers, HasClickHandlers, HasDoubleClickHandlers, HasDragEndHandlers, HasDragEnterHandlers, HasDragHandlers, HasDragLeaveHandlers, HasDragOverHandlers, HasDragStartHandlers, HasDropHandlers, HasFocusHandlers, HasGestureChangeHandlers, HasGestureEndHandlers, HasGestureStartHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasTouchCancelHandlers, HasTouchEndHandlers, HasTouchMoveHandlers, HasTouchStartHandlers, HasAttachHandlers, HasValueChangeHandlers<String>, HasHandlers, AutoDirectionHandler.Target, HasDirection, HasDirectionEstimator, EventListener, TakesValue<String>, Focusable, HasEnabled, HasFocus, HasName, HasText, HasValue<String>, HasVisibility, IsWidget, SourcesChangeEvents, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents, SourcesMouseEvents
Direct Known Subclasses:
PasswordTextBox

public class TextBox extends TextBoxBase
A standard single-line text box.

CSS Style Rules

  • .gwt-TextBox { primary style }
  • .gwt-TextBox-readonly { dependent style set when the text box is read-only }

Built-in Bidi Text Support

This widget is capable of automatically adjusting its direction according to the input text. This feature is controlled by ValueBoxBase.setDirectionEstimator(boolean), and is available by default when at least one of the application's locales is right-to-left.

Example

public class TextBoxExample implements EntryPoint {

  public void onModuleLoad() {
    // Make some text boxes. The password text box is identical to the text
    // box, except that the input is visually masked by the browser.
    PasswordTextBox ptb = new PasswordTextBox();
    TextBox tb = new TextBox();

    // TODO(ECC) must be tested.
    tb.addKeyPressHandler(new KeyPressHandler() {

      public void onKeyPress(KeyPressEvent event) {
        if (!Character.isDigit(event.getCharCode())) {
          ((TextBox) event.getSource()).cancelKey();
        }
      }
    });

    // Let's make an 80x50 text area to go along with the other two.
    TextArea ta = new TextArea();
    ta.setCharacterWidth(80);
    ta.setVisibleLines(50);

    // Add them to the root panel.
    VerticalPanel panel = new VerticalPanel();
    panel.add(tb);
    panel.add(ptb);
    panel.add(ta);
    RootPanel.get().add(panel);
  }
}

  • Constructor Details

    • TextBox

      public TextBox()
      Creates an empty text box.
    • TextBox

      protected TextBox(Element element)
      This constructor may be used by subclasses to explicitly use an existing element. This element must be an <input> element whose type is 'text'.
      Parameters:
      element - the element to be used
    • TextBox

      TextBox(Element element, String styleName)
  • Method Details

    • wrap

      public static TextBox wrap(Element element)
      Creates a TextBox widget that wraps an existing <input type='text'> element. This element must already be attached to the document. If the element is removed from the document, you must call Widget.removeFromParent().
      Parameters:
      element - the element to be wrapped
    • getMaxLength

      public int getMaxLength()
      Gets the maximum allowable length of the text box.
      Returns:
      the maximum length, in characters
    • getVisibleLength

      public int getVisibleLength()
      Gets the number of visible characters in the text box.
      Returns:
      the number of visible characters
    • setMaxLength

      public void setMaxLength(int length)
      Sets the maximum allowable length of the text box.
      Parameters:
      length - the maximum length, in characters
    • setVisibleLength

      public void setVisibleLength(int length)
      Sets the number of visible characters in the text box.
      Parameters:
      length - the number of visible characters