调整 Vaadin 图像大小

Resizing Vaadin Image

我正在将文件中的图像插入 UI。我按照 these 说明在 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);

但是我根本无法重新调整图像的大小。图像始终以全尺寸显示。

有什么方法可以不使用 CSS 来缩小图像?

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

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