Image srcset

Is it possible to define a source set for a com.vaadin.ui.Image?

In particular I would like to be able to handle different pixels densities -

Not out of the box. You could achieve that with an Extension, though, or perhaps with a JavaScript snippet. If you have a nice real life usage example, I’d recommend creating a feature ticket in .


Thanks for the quick response. I’m not up on extensions, but I suspect that the img element would already exist by the time the extension got started, in which case, the standard/default image would already be in place. JavaScript on a Panel would work. In my current situation I realised that an SVG solved the problem.

Do you have any thoughts on a feature ticket for adding the method setAttribute(String name, String value) to the Component interface, with the implementing class throwing an exception if the attribute is managed by Vaadin (e.g. width, height, etc…). e.g:

ExternalResource logoResourceX1 = new ExternalResource("");
ExternalResource logoResourceX2 = new ExternalResource("");

Image logo = new Image("logo", logoResourceX1);
logo.setAttribute("srcset", String.format("%s 1x, %s 2x", logoResourceX1.getURL(), logoResourceX2.getURL());


that API probably wouldn’t work, as it makes some assumptions about the client side implementation that don’t necessarily hold true - for example, there’s no guarantee that the element you’d actually want to add the attributes to is at the root.


Understood, feature ticket created -