我希望能够编写程序克隆一个小部件。我可以使用Dom.clone克隆小部件内的元素,但似乎无法从此克隆的元素创建一个小部件。这可能吗?
//somewhere in onModuleLoad()...
Button button = new Button("Original");
RootPanel.get().add(button);
//.....later on...
Element buttonCloneElement = DOM.clone(button.getElement(), true);
Widget buttonClone;
buttonClone = new Button(buttonCloneElement); //FAIL - No such constructor
buttonClone.setElement(buttonCloneElement); //FAIL - No such setter method
//This may work but looks messy to me
buttonClone.getElement().setInnerHTML(button.getElement().getInnerHTML());
//add the clone to the root panel??
RootPanel.get().add(buttonClone);
有没有其他克隆Widget的方式?