调整Vaadin图像的大小

Shi*_*iri 3 java vaadin vaadin7

我正在将文件中的图像插入到UI中.我按照这些说明在Vaadin 7.6.8中创建它.

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

但是我根本无法重新缩放图像或调整图像大小.图像始终以完整大小显示.

有没有一种方法可以缩小图像而不使用CSS?

Cod*_*roc 6

您可以指定图像组件的高度宽度,

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

  • 这有效,但如何保持图像的宽高比? (5认同)