2013-06-17 2 views
2

ID와 Ressource Bundle을 사용하여 이미지를 동적으로 변경하려고합니다.GWT 동적으로 이미지 변경

Element changedImage; 
/* imageID is the Id for the previous image */ 
changedImage = Document.get().getElementById("imageId"); 
/* And myImageBundle is the resource Bundle and icon the new image*/ 
changedImage.setInnerHTML(myImageBundle.icon().getHTML()); 

하지만 아무 일도 일어나지 않습니다. 동일한 이미지입니다. 내가 뭐 놓친 거 없니 ?

답변이나 제안을 보내 주셔서 감사합니다. 나는 해결책을 발견했습니다

-------- 솔루션 ---------------는 제대로 작동하지만, 어떻게 든 나는 그것이 아니다 생각 최고 . 그것이 도움이

private void switchImage( AbstractImagePrototype imageBundled) { 

    String newStyleFromImageBundle, value; 
    value = "style="; 

    newStyleFromImageBundle = extractStyle(value ,imageBundled.getHTML()); 

    Element e = Document.get().getElementById("imageHeaderLogo");  
    // removing the current style 
    e.removeAttribute("style");  
    // setting the new style with the previous one retrieved from the image bundled's html 
    e.setAttribute("style",newStyleFromImageBundle); 


} 

희망, 그것을 할 수있는 더 좋은 방법이 있다면 알려 주시기하거나 당신이 이제까지 본 적이 '최악 .. :-) : 모든 다음 기능에 있습니다.

답변

0

구체적으로는 applyTo이 대상이라고 생각합니다.

/*assuming that the element with id "imageId" is a real image 
element and is not undefined:*/ 
myImageBundle.icon().applyTo(Image.wrap(Document.get().getElementById("imageId"))); 

//editted to use Image.wrap 

위의 ID가 "imageId"나는 당신이 작성한 것을 시도했습니다

+0

와 이미지로 아이콘 (에 정의 된 이미지)를 적용한다 : 왜 그냥 다음을 수행하지 않습니다 하지만 다음 오류 메시지가 있습니다 : "요소에서 이미지로 변환 할 수 없습니다."나는 당신이 'asuming that ...'라고 말한 것과 링크가 있다고 생각합니다. id의 원래 소스는 AbstractImagePrototype img입니다. \t \t imgBundled = getMyImageBundle(). icon(); \t \t 이미지 이미지 = imgBundled.createImage(); \t \t image2.setStyleName ("imageCenterPanel"); \t \t image2.getElement(). setId ("imageId"); –

+0

죄송합니다. 위젯에 요소를 캐스트 할 수 없습니다. createImage를 통해 생성 된 이미지에 대한 참조가 있다면 (이는 image2가 의미하는 것이라고 생각합니다. 그런 다음 Document.get(). getElementById ("imageId") 대신 applyTo로 전달하십시오. (AbstractImagePrototype.ImagePrototypeElement) Document.get(). getElementById ("imageId")); – nightsRey

+0

당신은 물론 그냥 요소를 다른 요소로 래핑 할 수 있습니다. 이미지 : ... icon(). applyTo (Image.wrap (Document.get(). getElementById ("imageId")) – nightsRey