Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

gwt - How to add a custom widget to an element

GWT RootPanel.get("id") doesnt return me the div tags which are embedded in HTML elements.

ex. <body> <table> <tr> <td> <div id="x" /><td>...</table> ...

How do I get access to this div tag and "Add a widget".

One of the things I tried was to get the element from the widget or widget.getElement() and add this to the append this element to an element gotten from DOM.getElementById().

The widget does get added, however, all mouse clicks are lost and widget no longer responds. The widget is a composite of menu item, so the mouse clicks cause the menu item to drop but it just selects the text.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If by "HTML element" in your first sentence you actually mean "HTML widget", then you should use an HTMLPanel widget instead, and then simply use its add(Widget,String) or add(Widget,Element) method to add your widget within an existing sub-element.

If you're actually talking about the "A widget that has an existing parent widget may not be added to the detach list" assertion error, then starting with GWT 2.3, you can now wrap an existing DOM element within an HTMLPanel, and then use the same add methods as above:

HTMLPanel container = HTMLPanel.wrap(Document.get().getElementById("container"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...