vaadin - ExternalResource in Vaadin 10 - Custom Icons for Button
问题描述
I would like to use a custom icon from a picture file in Vaadin 10.
Up to Vaadin 8 it was possibleto load the icon file via ExternalResource:
public final static Resource MY_ICON = new ExternalResource("VAADIN/images/my_icon.png");
and then just use the resource as icon:
Button button = new Button("My Button text");
button.setIcon(MY_ICON);
The setIcon method in Vaadin 10 requires a Component as parameter. How can i load my Icon into a Component? Is there some out of the box solution in vaadin 10?
I would prefer a solution with pure java like in vaadin 7/8.
解决方案
我建议将您的图标文件作为/src/main/webapp/my_icon.png
(或者/src/main/resources/META-INF/resources/my_icon.png
如果打包为.jar
)。然后,您可以使用内置com.vaadin.flow.component.html.Image
组件在应用程序的任何位置使用它,例如add(new Image("my_icon.png", "My icon"));
.
推荐阅读
- macos - 如何在 MacOS 上使用 IMPDP Oracle 数据库
- python - 难倒简单的 numpy 问题 - 将 2D 数组附加到 3D 数组
- c# - 是否可以覆盖特定列的 CsvHelper 的默认映射,如果它下面的字段是空字符串 - 写别的东西?
- android - 获取实例导致的 kotlin.UninitializedPropertyAccessException
- python - 如何对匿名数据集进行特征工程?
- python - 数据框列不会在python中转换为浮点数据类型
- javascript - 为什么我的排序算法没有正确排序?
- flyway - 将 Flyway 集成到现有数据库中
- nlp - 将单词分类为带有定义的预定义主题
- java - java中的一个简单循环字符串需要审查