简体   繁体   English

将按钮添加到gwt小部件

[英]Add Button to gwt widgets

How can i add a button without text only with marker for forward and backward action for example for widget ListBox in gwt? 如何添加仅带有标记的不带文本的按钮进行前进和后退操作,例如gwt中的小部件ListBox? i tried something like this: 我尝试过这样的事情:

 Button btn = new Button("Forward");
        btn.setHTML(("<img border='0' src='image\\B_forwards.png' />"));

but can't get the picture to show on button. 但无法将图片显示在按钮上。 在此处输入图片说明

You don't need a button. 您不需要按钮。 Add an Image widget, and add a ClickHandler to it. 添加一个图像小部件,并向其添加一个ClickHandler。

If you just want to add an image to a normal GWT Button, then PushButton is the way to go: 如果您只想将图像添加到普通的GWT按钮,则可以使用PushButton:

PushButton pushButton = new PushButton(new Image("test.png"));

Otherwise, if you just want to have a clickable image, you still can do that: 否则,如果您只想拥有可点击的图像,则仍然可以这样做:

public interface MyResources extends ClientBundle{
    MyResources INSTANCE = GWT.create(AppImages.class);
    @Source("image.gif")
    ImageResource image();
}

Image image = new Image( MyResources.INSTANCE.image() );
image.addClickHandler(new ClickHandler() {
     public void onClick(ClickEvent event) {
         // do whatever you want
     }
} );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM