我希望以编程方式克隆一个小部件。我可以使用 Dom.clone 在 Widget 中克隆 Element,但我似乎无法从这个克隆的元素创建 Widget。这可能吗?
//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的方法?
最佳答案
buttonClone = Button.wrap(buttonCloneElement)
关于java - GWT 使用 DOM.clone 克隆一个小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2025061/