【问题标题】:GWT - enable button on KeyDownEvent in RichTextAreaGWT - 在 RichTextArea 中的 KeyDownEvent 上启用按钮
【发布时间】:2014-05-12 20:03:00
【问题描述】:

我有以下处理程序

textArea.addKeyDownHandler(new KeyDownHandler() {
            @Override
            public void onKeyDown(KeyDownEvent event) {
                //here
            }
        });

我需要启用 ID 为“idsave”的保存按钮,但我无法引用该按钮。 我是 GWT 的新手,我们将不胜感激。

【问题讨论】:

  • 保存按钮的代码在哪里?你有保存按钮的参考吗?
  • 问题解决了吗?

标签: gwt richtextarea


【解决方案1】:

通常,您不会在 GWT 中使用元素 ID。如果你创建了一个按钮,你可以简单地使用它:

private Button saveButton;
...

saveButton = new Button("Save");
textArea.addKeyDownHandler(new KeyDownHandler() {
     @Override
     public void onKeyDown(KeyDownEvent event) {
          saveButton.setEnabled(true);
     }
});

【讨论】:

  • OP 说 但我无法引用按钮
  • 无法在KeyDownHandler 中引用saveButton,因为按钮不是final
【解决方案2】:

如果您没有按钮的引用,请尝试使用 id。

// get element by id
Element saveButtonElement = RootPanel.get("idsave").getElement(); 

// remove disabled attribute to make it enable
saveButtonElement.removeAttribute("disabled"); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多