简体   繁体   English

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

[英]How to show pictures in my UI working with vaadin

I´m simply trying to show a picture in vaadin layout and I´m working with vaadin 13. 我只是想以vaadin布局显示图片,并且正在使用vaadin 13。

I´m not sure where the problem is. 我不确定问题出在哪里。 I checked many times the path of my picture and if it is in the right package or not, but everything seems right. 我检查了很多遍图片的路径,以及是否在正确的包装中,但是一切似乎都正确。 So I can´t understand why it´s not displaying my picture. 所以我不明白为什么它不显示我的照片。

@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);

Actually it´s looking like that. 其实看起来像那样。 在此处输入图片说明

File path structure: 文件路径结构: 在此处输入图片说明

Problem is solved thanks to @KasparScherrer @KasparScherrer解决了问题

When I changed my src/main/resources folder to src/main/webapp it works, but then my maven project is telling me that my project is missing the required src/main/resources folder. 当我将src / main / resources文件夹更改为src / main / webapp时,它可以工作,但是随后我的Maven项目告诉我我的项目缺少所需的src / main / resources文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM