Image component is designed for displaying images from different sources. The component can be bound to a data container or configured programmatically.

Component’s XML-name: image.


The Image component can display the value of an entity attribute of FileRef or byte[] type. In the simplest case image can be declaratively associated with data using the dataContainer and property attributes:

@Table(name = "UIEX1_PERSON")
@Entity(name = "uiex1_Person")
public class Person {
    @Column(name = "ID", nullable = false)
    private UUID id;

    @Column(name = "STATUS")
    private java.lang.Boolean status;

    @Column(name = "NAME", nullable = false)
    private String name;

    @Column(name = "IMAGE")
    private FileRef image;

    public java.lang.Boolean getStatus() {
        return status;

    public void setStatus(java.lang.Boolean status) {
        this.status = status;
<data readOnly="true">
    <instance id="personDc"
        <fetchPlan extends="_base"/>
<layout spacing="true">
        <image id="fileRefImage"

In the example above, the component displays the image attribute of the Person entity located in the personDc data container.


Alternatively, the Image component can display images from different resources. You can set the resource type declaratively using the image elements listed below:

  • classpath - resource in the classpath.

  • file - resource in the file system.

  • relativePath - resource in the application directory.

  • theme - theme resource.

  • url - resource which can be loaded from the given URL.

For example:

        <classpath path="ui/ex1/screen/component/image/jmix-logo.png"/>

Also, you can do it programmatically, using one of the resource types.

Resource Settings

  • bufferSize - size of the download buffer in bytes used for this resource.

  • cacheTime - length of cache expiration time in milliseconds.

  • mimeType - MIME type of the resource.

For example:

        <url url=";s=200"


  • alternateText - sets an alternate text for an image in case the resource is not set or unavailable.

  • scaleMode - applies the scale mode to the image. The following scale modes are available:

    • FILL - the image will be stretched according to the size of the component.

    • CONTAIN - the image will be compressed or stretched to the minimum dimension of the component while preserving the proportions.

    • COVER - the image will be compressed or stretched to fill the entire area of the component while maintaining the component’s proportions. If the image proportions do not match the component’s proportions, then the image will be clipped to fit.

    • SCALE_DOWN - the content changes size by comparing the difference between NONE and CONTAIN to find the smallest concrete size of the object.

    • NONE - the image will retain its real size.


To programmatically manage the Image component, use the following methods:

  • setValueSource() - sets the data container, and the entity attribute name. Only FileRef and byte[] type of attributes are supported.

    The data container can be set programmatically, for example, to display images in table cells:

    <data readOnly="true">
        <collection id="personsDc"
            <fetchPlan extends="_base"/>
            <loader id="personsDl">
                    <![CDATA[select e from uiex1_Person e]]>
    <layout spacing="true">
            <groupTable id="personsTable"
                    <column id="name"/>
    private GroupTable<Person> personsTable;
    private UiComponents uiComponents;
    public void onInit(InitEvent event) {
        personsTable.addGeneratedColumn("image", entity -> {
            Image<FileRef> image = uiComponents.create(Image.NAME);
            image.setValueSource(new ContainerValueSource<>(personsTable.getInstanceContainer(entity), "image"));
            return image;
  • setSource() - sets the content source for the component. The method accepts the resource type and returns the resource object that can be configured using the fluent interface.

    <layout spacing="true">
            <image id="programmaticImage"/>
    private Image<FileRef> programmaticImage;
    public void onInit(InitEvent event) {
        String address = "";
        URL url = null;
        try {
            url = new URL(address);
        } catch (MalformedURLException e) {

Resource Types

You can use one of the following resource types implementing the Resource interface or extend it to create a custom resource:

  • ClasspathResource - an image located in the classpath.

  • FileResource - an image stored in the file system.

  • RelativePathResource - an image stored in a directory of the application.

  • StreamResource - an image from a stream.

  • ThemeResource - a theme image, for example, VAADIN/themes/yourtheme/some/path/image.png.

  • UrlResource - an image that can be loaded from the given URL.

Events and Handlers

To generate a handler stub in Jmix Studio, select the component in the screen descriptor XML or in the Component Hierarchy panel and use the Handlers tab of the Component Inspector panel.

Alternatively, you can use the Generate Handler button in the top panel of the screen controller.


See ClickEvent.



The SourceChangeEvent is sent when a source of an image is changed and has the following methods:

  • getNewSource()

  • getOldSource()

public void onImageSourceChange(ResourceView.SourceChangeEvent event) {
            .withCaption("Old source was: " + event.getOldSource() +
                    "; new source is: " + event.getNewSource());

Programmatic registration of the event handler: use the addSourceChangeListener() component method.

All XML Attributes

You can view and edit attributes applicable to the component using the Component Inspector panel of the Studio’s Screen Designer.