如何使用Vaadin在我的UI中显示图片

时间:2019-06-15 09:53:46

标签: java image spring-boot vaadin

我只是想以vaadin布局显示图片,并且正在使用vaadin13。

我不确定问题出在哪里。我检查了很多遍图片的路径,以及是否在正确的包装中,但是一切似乎都正确。 所以我不明白为什么它不显示我的照片。

@SuppressWarnings("serial")
@Route(value = "", layout = MainView.class)
public class Overview extends VerticalLayout {

public Overview() {
    Label helloLabel = new Label("Hello User!");

    // Html img = new Html("<img src='/images/homePicture.jpg'>");
    // add(img);
    Image i = new Image("images/homePicture.jpg", "Alternative image text");
    add(i);


    Button secondButton = new Button("show");
    Dialog dialog = new Dialog();
    dialog.add(i);
    secondButton.addClickListener(event -> dialog.open());
    add(secondButton);

实际上看起来像那样。 enter image description here

文件路径结构: enter image description here

1 个答案:

答案 0 :(得分:0)

@KasparScherrer解决了问题

当我将src / main / resources文件夹更改为src / main / webapp时,它可以工作,但是随后我的Maven项目告诉我我的项目缺少所需的src / main / resources文件夹。