Vaadin 8网格:如何在网格单元中将图像显示为工具提示?

Vaadin 8网格:如何在网格单元中将图像显示为工具提示?,vaadin,vaadin8,vaadin-grid,Vaadin,Vaadin8,Vaadin Grid,我在网格单元中有一个图像,我想将放大的图像显示为工具提示。应该可以使用“setDescriptionGenerator”。我尝试了以下方法: grid.addComponentColumn(探测->{ Image Image=newimage(“,newthemeresource”(“img/”+probe.getImage()); 图像设置宽度(35,单位百分比); 图像设置高度(35,单位百分比); 返回图像; }).setCaption(“结构”).setDescriptionGenera

我在网格单元中有一个图像,我想将放大的图像显示为工具提示。应该可以使用“setDescriptionGenerator”。我尝试了以下方法:

grid.addComponentColumn(探测->{
Image Image=newimage(“,newthemeresource”(“img/”+probe.getImage());
图像设置宽度(35,单位百分比);
图像设置高度(35,单位百分比);
返回图像;
}).setCaption(“结构”).setDescriptionGenerator(探测->{
Image Image=newimage(“,newthemeresource”(“img/”+probe.getImage());
返回图像;
});
但我得到的错误是,我无法返回图像。似乎使用“setDescriptionGenerator”只能设置字符串。是否可以编写自定义描述生成器?请给我举个例子


谢谢你的帮助

只要您在此处只能返回字符串类型,我将为您提供以下解决方法:

grid.addComponentColumn(探测->{
Image Image=newimage(“,newthemeresource”(“img/”+probe.getImage());
图像设置宽度(35,单位百分比);
图像设置高度(35,单位百分比);
返回图像;
}).setCaption(“结构”).setDescriptionGenerator(探测->{
字符串imgSource=“img/”+probe.getImage();
字符串html=“”;
返回html;
});
从开始,您应该设置一个同时传递
ContentMode.HTML

grid.addComponentColumn(probe -> {
    Image image = new Image("", new ThemeResource("img/" + probe.getImage()));
    image.setWidth(35, Unit.PERCENTAGE);
    image.setHeight(35, Unit.PERCENTAGE);

    return image;
}).setCaption("Structure").setDescriptionGenerator(probe -> {
    String imgSource = "img/" + probe.getImage();
    String html = "<img src=\" " + imgSource + "\" width=\"100\" height=\"100\">";
    return html;
}, ContentMode.HTML);
grid.addComponentColumn(探测->{
Image Image=newimage(“,newthemeresource”(“img/”+probe.getImage());
图像设置宽度(35,单位百分比);
图像设置高度(35,单位百分比);
返回图像;
}).setCaption(“结构”).setDescriptionGenerator(探测->{
字符串imgSource=“img/”+probe.getImage();
字符串html=“”;
返回html;
},ContentMode.HTML);

谢谢!这真是个好主意。你知道我要把图像放在哪里吗?对于主题资源,我将图像放在src\main\webapp\VAADIN\themes\mytheme\img中。但是在html中找不到图像。我还使用src\main\webapp\WEB-INF\images中的图像尝试了Vaadin basepath。这仍然不起作用。请尝试
。/VAADIN/themes/myteme/img
或不使用这些
。还要确保您的图像名称包含许多路径(甚至是带有file:///的绝对路径),但我总是将html显示为文本。在网格描述中似乎无法识别html。我找到了这个链接:你让它在你的Vaadin 8网格中工作了吗?很抱歉很长时间没有响应。希望能帮助你谢谢你试图帮助我!链接指向常规工具提示的CSS,在mytheme中已经设置为这样。但是,这似乎不适用于网格单元工具提示。我找了一些类似于v-grid-cell-tooltip的东西,但什么也找不到。