Sets the icon of the component.
An icon is an explanatory graphical label accompanying a user interface
component, usually shown above, left of, or inside the component. Icon is
closely related to caption (see
#setCaption(String))
and is usually displayed horizontally before or after it, depending on
the component and the containing layout.
The image is loaded by the browser from a resource, typically a
com.vaadin.server.ThemeResource.
// Component with an icon from a custom theme
TextField name = new TextField("Name");
name.setIcon(new ThemeResource("icons/user.png"));
layout.addComponent(name);
// Component with an icon from another theme ('runo')
Button ok = new Button("OK");
ok.setIcon(new ThemeResource("../runo/icons/16/ok.png"));
layout.addComponent(ok);
The icon of a component is, by default, managed and displayed by the
layout component or component container in which the component is placed.
For example, the
VerticalLayout component shows the icons
left-aligned above the contained components, while the
FormLayoutcomponent shows the icons on the left side of the vertically laid
components, with the icons and their associated components left-aligned
in their own columns. The
CustomComponent does not manage the
icon of its composition root, so if the root component has an icon, it
will not be rendered.
An icon will be rendered inside an HTML element that has the
v-icon CSS style class. The containing layout may enclose an icon
and a caption inside elements related to the caption, such as
v-caption .