image
image displays an image from a data container, application resource, URL, or programmatic source.
XML Element |
|
|---|---|
Java Class |
|
Basics
Set the resource attribute to display an image available to the application:
<image resource="icons/jmix-icon.png" height="10em" width="10em"/>
Data-aware image
Set dataContainer and property to display a FileRef or byte[] entity attribute. The example binds both the upload field and image to the content property, so a newly uploaded value is displayed immediately:
<data>
<instance id="pictureDc"
class="io.jmix.uisamples.entity.Picture"
fetchPlan="_local"/>
</data>
<layout>
<fileUploadField label="Load new image" dataContainer="pictureDc" property="content"
clearButtonVisible="true" fileNameVisible="true" acceptedFileTypes=".png"/>
<image id="numberField" height="10em" width="10em"
alternateText="No picture loaded"
dataContainer="pictureDc" property="content"/>
</layout>
URL and Programmatic Sources
Set resource to an external URL. For a source created at runtime, call setSrc() with a DownloadHandler. The example shows both approaches.
Static web resources normally reside under /static, /public, /resources, or /META-INF/resources on the classpath. See Static Public Resources when they must be available without authentication.
<layout justifyContent="BETWEEN" classNames="horizontal-layout">
<vbox padding="false" width="AUTO" alignItems="CENTER">
<h4 text="URL resource"/>
<image resource="https://www.jmix.io/uploads/framework_image_9efadbc372.svg"
height="15em" width="15em"/>
</vbox>
<vbox padding="false" width="AUTO" alignItems="CENTER">
<h4 text="Programmatic resource"/>
<image id="imageProgrammaticResource"
height="15em" width="15em"/>
</vbox>
</layout>
protected static final String SRC_PATH = "/META-INF/resources/icons/image-sample.svg";
@ViewComponent
protected JmixImage<?> imageProgrammaticResource;
@Subscribe
protected void onInit(InitEvent event) {
imageProgrammaticResource.setSrc(DownloadHandler.forClassResource(getClass(), SRC_PATH));
}
Theme Variants
Use themeNames to control how an image fits within its dimensions.
| Variant | Description | Supported By |
|---|---|---|
|
Stretches the image to fill both dimensions. |
Aura, Lumo |
|
Scales the image to fit without cropping. |
Aura, Lumo |
|
Scales and crops the image to cover its area. |
Aura, Lumo |
|
Uses the smaller result of the natural size and |
Aura, Lumo |
Attributes
Common attributes serve the same purpose for all components.
The following attributes are specific to image:
| Name | Description | Default |
|---|---|---|
Provides accessible alternative text and fallback text when the image cannot be loaded. |
— |
|
Specifies the location of the image. See URL and Programmatic Sources. |
— |
|
Applies one or more variants listed in Theme Variants. |
— |
Handlers
Common handlers are configured in the same way for all components.
The following handlers are specific to image:
| Name | Description |
|---|---|
Fires when the image is clicked. Use the |