java 设置 GWT 小部件的 id

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7380765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:44:00  来源:igfitidea点击:

Setting a GWT widget's id

javagwt

提问by Elbek

I have a FlowPanel object on gwt application.

我在 gwt 应用程序上有一个 FlowPanel 对象。

FlowPanel flowPanel = new FlowPanel();
flowPanel.add(new Button("Edit"));
flowPanel.add(new Button("Delete"));
flowPanel.getElement().setId("idOfFlow");

It gives me the following error:

它给了我以下错误:

flowPanel.getElement().setId("idOfFlow") = No such instance method:
 'void com.google.gwt.core.client.JavaScriptObject$.setId (java.lang.String)'

How can I set the Id of the FlowPanel?

如何设置 的Id FlowPanel

回答by Ammar

I am using GWT 2.4.0, this code works fine.

我正在使用 GWT 2.4.0,这段代码工作正常。

FlowPanel panel = new FlowPanel();
panel.getElement().setId("panel-id");

or

或者

FlowPanel panel = new FlowPanel();
DOM.setElementProperty(panel.getElement(), "id", "panel-id");