bubbles
bubbles

Reputation: 881

What the easiest way to add a image to my GWT application

I have .jpg file that I want to display. I have some Horizontal and Vertical panels and I would like to have it somewhere in there. It is a fairly large image but I would like to make a class or an object that will scale it down for me.

My first thought was to just put it in a Horizontal Panel like so but that does not seem to work as I intended

HorizontalPanel picturePanel = new HorizontalPanel();
picturePanel.setPixelSize(600, 300);
picturePanel.addStyleName("pic");

Css.css

.pic
{
    background: url(images/mypic.jpg);
    height: auto;
    width: auto;
}

I'd like to set the pixel size of an object (panel) and add an image to that panel so that it fits within the bounds (while making sure the ratio is the same as in the picture) so I can programatically add it to a panel somewhere.

Upvotes: 1

Views: 5358

Answers (2)

Hein B
Hein B

Reputation: 67

This works:

Image image = new Image();

Image.setWidth("100px");

image.setUrl('http://127.0.0.1:8888/images/accounts.png');

Loads image form local server and will limit size of image.

Upvotes: 1

Ashok
Ashok

Reputation: 617

public interface MyResources extends ClientBundle {

MyResources INSTANCE = GWT.create(MyResources.class);

@Source("logo.png")
ImageResource logo();
}

in your view class

Image logo = new Image(MyResources.INSTANCE.logo()); 

add image to panel; set resolution to your panel and also set the same to your image by using

setPixelSize(int,int);

Upvotes: 6

Related Questions