我有一个奇怪的问题要解决。我有一个 GWT Textarea,无法向其中输入文本,但是,我可以自动设置文本。
我已经尝试过
textBox.setEnabled(true);
textBox.setFocus(true);
textBox.setReadOnly(false);
但它并没有改变任何东西。在浏览 css 文件时,在我看来一切正常。
这是“整个”源代码:
private Input(AbsolutePanel canvas) {
textBox = new MouseEventTextBox();
textBox.setStylePrimaryName(PRIMARY_STYLE);
textBox.addKeyUpHandler(this);
textBox.addKeyDownHandler(this);
textBox.addFocusHandler(this);
textBox.addBlurHandler(this);
textBox.setEnabled(true);
textBox.setFocus(true);
textBox.setReadOnly(false);
textBox.setText("Just an apple"); // Works, text is set but not editable
canvas.add(textBox, -1000, -1000);
}
private class MouseEventTextBox extends TextArea{
public MouseEventTextBox() {
super();
sinkEvents(Event.MOUSEEVENTS);
}
public void onBrowserEvent(Event event) {
// Call the superclass' implementation first.
super.onBrowserEvent(event);
if ((DOM.eventGetButton(event) == Event.BUTTON_LEFT) && (DOM.eventGetType(event) == Event.ONMOUSEUP)) {
this.setReadOnly(false);
DOM.eventCancelBubble(event, true);
}
}
}
CSS
border-width: 0px;
background-color: #fffde5;
padding-top: 2px;
padding-left: 3px;
padding-right: 3px;
padding-bottom: 1px;
z-index: 50;
overflow: hidden;
也许,有人可以给我一个提示或知道这里出了什么问题?
非常感谢你!
您代码的可疑部分是:
textBox.addKeyUpHandler(this);
textBox.addKeyDownHandler(this);
textBox.addFocusHandler(this);
textBox.addBlurHandler(this);
这意味着,this
工具KeyUpHandler
,KeyDownHandler
,FocusHandler
和BlurHandler
。不幸的是,您没有向我们展示处理这些事件的方法。
我敢打赌,你的onKeyDown
方法有问题。当我阻止KeyDownEvent
事件 ( stopPropagation
, preventDefault
)时,我能够实现相同的行为。
检查您的浏览器控制台是否有错误。如果没有,注释掉textBox.addKeyDownHandler(this);
一行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句