[英]GWT TextArea - Resize Handler
Some browsers show for HTML Textareas a handle to resize the textbox. 一些浏览器为HTML Textareas显示一个调整文本框大小的句柄。 Is there any way to react to this resize events in GWT? 有什么办法可以对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());
"It doesn't look like you can specifically attach events to resizing a textarea. The resize event fires when the window is resized. " “看起来您不能专门将事件附加到调整文本区域的大小 。 当调整窗口大小时,会触发resize事件。 ”
https://stackoverflow.com/a/2096352/1467482 https://stackoverflow.com/a/2096352/1467482
The question already is two years old, but for them who are brought by Google to this question I have a solution. 这个问题已经有两年历史了,但是对于由Google提出这个问题的人,我有一个解决方案。
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;
}
}
}
});
}
}
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.