Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I wish to programatically clone a widget. I am able to clone the Element inside the Widget with Dom.clone but I don't seem to be able to create a Widget from this cloned element. Is this possible?

        //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);

Is there another way of cloning the Widget?

See Question&Answers more detail:os

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

1 Answer

buttonClone = Button.wrap(buttonCloneElement)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...