0

Some browsers show for HTML Textareas a handle to resize the textbox. Is there any way to react to this resize events in GWT?

I tried it with this code, but the event is not triggered:

TextArea textArea = new TextArea();

textArea.addHandler(new ResizeHandler() {

    @Override
    public void onResize(ResizeEvent event) {
        System.out.println("resize");

    }
}, ResizeEvent.getType());
jan
  • 3,923
  • 9
  • 38
  • 78

2 Answers2

1

"It doesn't look like you can specifically attach events to resizing a textarea. The resize event fires when the window is resized."

https://stackoverflow.com/a/2096352/1467482

Community
  • 1
  • 1
Vjeetje
  • 5,314
  • 5
  • 35
  • 57
  • If you find the same post,Since you don't have enough reputation , You should flag it as duplicate,Or make a comment with that question. – Suresh Atta Aug 14 '13 at 04:36
  • It's not a real duplicate in my opinion. I think this question is useful for designers of GWT without prior knowledge of Javascript. – Vjeetje Aug 14 '13 at 10:17
0

The question already is two years old, but for them who are brought by Google to this question I have a solution.

You can use the mouse-down, mouse-move and mouse-up events to react on resizing of the text area. Here is a skeleton code:

TextArea textArea = new TextArea();
...
textArea.addMouseDownHandler(new MouseDownHandler() {
  private HandlerRegistration mouseMoveUpRegistration;
  private int lastWidth;
  private int lastHeight;

  @Override
  public void onMouseDown(MouseDownEvent event) {
    lastWidth = getOffsetWidth();
    lastHeight = getOffsetHeight();

    if (mouseMoveUpRegistration == null) {
      mouseMoveUpRegistration = Event.addNativePreviewHandler(new NativePreviewHandler() {
        @Override
        public void onPreviewNativeEvent(NativePreviewEvent event) {
          if (event.getTypeInt() == Event.ONMOUSEMOVE || event.getTypeInt() == Event.ONMOUSEUP) {
            int width = getOffsetWidth();
            int height = getOffsetHeight();
            if (width != lastWidth || height != lastHeight) {
              // do whatever you want to to while still resizing
              lastWidth = width;
              lastHeight = height;
            }

            if (event.getTypeInt() == Event.ONMOUSEUP) {
              // do whatever you want to do when resizing finished
              // perhaps check actual and initial size to see if the size really changed
              /* mouse up => additionally remove the handler */
              if (mouseMoveUpRegistration != null) {
                mouseMoveUpRegistration.removeHandler();
                mouseMoveUpRegistration = null;
              }
            }
          }

      });
    }
  }

});

Johanna
  • 5,223
  • 1
  • 21
  • 38