Resizing Vaadin Image

自作多情 提交于 2021-01-27 14:51:53

问题


I am inserting an image from file into a UI. I am creating it in Vaadin 7.6.8 by following these instructions.

String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
FileResource resource = new FileResource(new File(basepath + "/WEB-INF/images/image.png"));
Image image = new Image("", resource);

However I am unable to rescale or resize the image at all. The image is always being displayed in full size.

Is there a way that I can scale down the image without using CSS ?


回答1:


You can specify height and width of the image component,

FileResource resource = new FileResource(new File("D:/image.jpg"));
Image image = new Image("", resource);
image.setWidth(200, Unit.PIXELS);
image.setHeight(200, Unit.PIXELS);


来源:https://stackoverflow.com/questions/38956441/resizing-vaadin-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!