2012-07-04 2 views
0

테이블 셀 내부에 이미지를 표시하기 위해 gwt를 사용하고 있습니다. 동적 이미지이므로 하드 코딩 할 필요가 없지만 내부에 액트 정품 이미지가 표시되지 않습니다. 여기 내 코드는 ...입니다GWT TableCellElement가 배경 이미지를 표시하지 않습니다.

내 UiBinder입니다 뭔가를해야만 같은 :

<table> 
     <tr><td ui:field="tableCellElement"/></tr> 
    </table> 
내 발표자 방법의 요소에 액세스

:

void someMethod(Image patterImage) { 
     tableCellElement.setBackgroundImage("url('"+patternImage.getUrl()+"')"); 
     // and I have tried this without using url as well but it doesn't work 
     // DOM.setstyleattribute also doesn't work... 
    } 

코드는 성공적으로 실행하지만이 표시되지 않습니다 이미지, 나는 순간 IE9를 사용하고 있지만 IE8과 7에서도 시도했다.

나는 누군가가 그것을 밖으로 정렬 수 있다면 정말 감사

..는 CSS로 해결 될 수 있지만, 여기에 우리가 100 개 이미지가 있다면 나는 각 이미지에 대한 100 CSS를 정의 할 수 있도록 우리의 이미지가 동적 알고 나를 위해.

+0

후 당신의 소유자 클래스를 UI 바인더 템플릿. UiField tableCellElement에 com.google.gwt.dom.client.TableCellElement 클래스를 사용했습니다. 하지만'TableCellElement'는'setBackgroundImage'를 정의하지 않습니다. –

답변

0

코드는 기본적으로 괜찮습니다. 이미지를 볼 수없는 이유는 아마도 td의 기본 크기가 0 일뿐입니다.

배경 이미지는 요소 크기에 영향을 미치지 않으므로 수동으로 설정해야합니다. 모든 이미지의 크기가 동일한 경우에는 UiBinder에 한 번 설정할 수 있습니다

<ui:style> 
    .myTableCell { 
    width: 32px; 
    height: 32px; 
    } 
</ui:style> 

... 

<table> 
    <tr> 
    <td class="{style.myTableCell}" ui:field="tableCellElement"></td> 
    </tr> 
</table> 

그렇지 않으면, 프로그래밍 방식으로 설정 :

Style style = tableCellElement.getStyle(); 

style.setBackgroundImage("url('"+patternImage.getUrl()+"')"); 
style.setWidth(patternImage.getWidth(), Unit.PX); 
style.setHeight(patternImage.getHeight(), Unit.PX); 
관련 문제