avatar
avatar is a content area that displays an image, typically a photo of a person or a company logo.
XML Element |
|
|---|---|
Java Class |
|
Basics
The following example demonstrates a name-derived abbreviation, an explicit abbreviation, and an image supplied by the view controller.
<hbox padding="false" wrap="true">
<avatar name="Homer Jay Simpson"/>
<avatar name="Homer Jay Simpson" abbreviation="HS"/>
<avatar id="avatarWithImage"/>
</hbox>
@ViewComponent
protected Avatar avatarWithImage;
@Subscribe
protected void onInit(InitEvent event) {
avatarWithImage.setImageHandler(
DownloadHandler.forClassResource(getClass(), "/META-INF/resources/icons/homer-simpson.png")
);
}
An avatar without any of these attributes displays a fallback image.
Image Resource
The avatar component can display an image from different resources. You can set a path to the resource declaratively with the image attribute, or set it programmatically.
Static Image
An image can be served statically by the application.
By default, static content is served from /static, /public, /resources, or /META-INF/resources directories of the classpath (see details in the Spring Boot documentation).
-
In XML:
For example, if your image is located under
/src/main/resources/META-INF/resources, such as/src/main/resources/META-INF/resources/icons/mary.png, you can specify the image as follows:<avatar image="/icons/mary.png"/> -
In Java:
avatar.setImage("/icons/mary.png");
URL Image
Similarly, an image can be loaded from an arbitrary URL.
-
In XML:
<avatar image="https://www.jmix.io/_nuxt/img/banner-img.d30b0fa.svg"/> -
In Java:
avatar.setImage("https://www.jmix.io/_nuxt/img/banner-img.d30b0fa.svg");
Image Provided by a DownloadHandler
An image can be provided by a DownloadHandler.
Use the com.vaadin.flow.server.streams.DownloadHandler factory methods to create a handler for the image source.
For example, DownloadHandler.forClassResource() creates a handler for an image located in the application classpath.
@ViewComponent
protected Avatar avatarWithImage;
@Subscribe
protected void onInit(InitEvent event) {
avatarWithImage.setImageHandler(
DownloadHandler.forClassResource(getClass(), "/META-INF/resources/icons/homer-simpson.png")
);
}
Theme Variants
Use the themeNames attribute to apply one or more theme variants.
| Variant | Description | Supported By |
|---|---|---|
|
Makes the avatar extra small. |
Aura, Lumo |
|
Makes the avatar small. |
Aura, Lumo |
|
Makes the avatar large. |
Aura, Lumo |
|
Makes the avatar extra large. |
Aura, Lumo |
|
Applies a filled surface style. |
Aura |
Attributes
The following attributes are specific to avatar:
| Name | Description | Default |
|---|---|---|
Sets an abbreviation to display in the component. |
— |
|
Specifies the background color for the avatar component. |
— |
|
Specifies a path to an image resource. |
— |
|
Sets a name of the avatar holder. |
— |
The following shared attributes are supported by avatar: