简体   繁体   中英

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? 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.

If you just want to add an image to a normal GWT Button, then PushButton is the way to go:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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