Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gwt 如何更改TabLayoutPanel选项卡中的图像?_Gwt_Styling - Fatal编程技术网

Gwt 如何更改TabLayoutPanel选项卡中的图像?

Gwt 如何更改TabLayoutPanel选项卡中的图像?,gwt,styling,Gwt,Styling,目前,我有一个TabLayoutPanel,在我的UiBinder的标签中有一个用于面板的图像URL。是否有一种方法可以在选择选项卡后使用UiBinder将图像调出?如果不是,我将如何在CSS中实现这一点?这有可能吗 谢谢 <g:TabLayoutPanel ui:field="homePanel" barUnit='PX' barHeight='100'> <g:tab> <g:header> <

目前,我有一个TabLayoutPanel,在我的UiBinder的标签中有一个用于面板的图像URL。是否有一种方法可以在选择选项卡后使用UiBinder将图像调出?如果不是,我将如何在CSS中实现这一点?这有可能吗

谢谢

<g:TabLayoutPanel ui:field="homePanel" barUnit='PX' barHeight='100'>
        <g:tab>
        <g:header> 
            <img src = "images/sprites_01.png"></img> 
        </g:header>
        <g:Label>Hello, world!</g:Label>
        </g:tab>
        <!-- First Tab -->
        <g:tab>
        <g:header>
            <img src = "images/sprites_02_notselected.png"></img>
        </g:header>
            <my:FirstTabWidget ui:field="TabWidgetOne">    </my:FirstTabWidget>
        </g:tab>

你好,世界!

等等。

.ui.xml
文件中,在img元素中放置
ui:field
属性:

<g:HTMLPanel>
    <g:TabLayoutPanel ui:field="homePanel" barUnit='PX' barHeight='100'>
        <g:tab>
            <g:header> 
                <img ui:field="tab1Img" src = "images/sprites_01.png"></img> 
            </g:header>
            <g:HTML>My first tab</g:HTML>
        </g:tab>
        <g:tab>
            <g:header>
                <img ui:field="tab2Img" src = "images/sprites_02_notselected.png"></img>
            </g:header>
            <g:HTML>My second tab</g:HTML>
        </g:tab>
    </g:TabLayoutPanel>
</g:HTMLPanel>
@UiField ImageElement tab1Img;
@UiField ImageElement tab2Img;
在TabLayoutPanel中添加SelectionHandler,并根据需要交换图像src属性:

homePanel.addSelectionHandler(new SelectionHandler<Integer>(){
    public void onSelection(SelectionEvent<Integer> evt){
        //change the img source here:
        tab1Img.setSrc("myOtherImage1.png");
        tab2Img.setSrc("myOtherImage2.png");
    }
});
homePanel.addSelectionHandler(新的SelectionHandler(){
选举时公共无效(SelectionEvent evt){
//在此处更改img源:
表1img.setSrc(“myOtherImage1.png”);
tab2Img.setSrc(“myOtherImage2.png”);
}
});

可以选择选项卡的元素(使用
ui:field
属性),然后使用。请粘贴您的
.ui.xml
文件,以便我能做出正确的回答。@GilbertoTorrezan添加了一些示例代码。由于某些原因,每次我尝试编译时,它都会在我使用ImageResource时给我一个延迟绑定错误。你可能知道为什么会这样吗?顺便说一句,我非常感谢您的帮助--我知道您想要什么,这是有意义的。在这种情况下,请尝试使用
tab1Img.setSrc(myImageResource.getSafeUri())。中似乎有错误,因此简单地声明映像存在就是抛出此错误。您以前实现过这个吗?是的,但要实现它,您的
ui.xml
的根元素必须是一个。所以,换句话说,您的TabLayoutPanel必须是HTMLPanel的孩子。我更新了示例以反映这一点。我的意思是“根部件”而不是“根元素”。。。根元素当然是
元素。