如何在vaadin标签上添加html格式?

问题描述 投票:0回答:1

我想在vaadin标签上添加html格式的字符串。该字符串来自数据库,直接进入标签,必须使用加粗文本,换行符和其他一些花哨的文本格式设置其格式。我找到了几种解决方案,但这些解决方案是针对旧版本的vaadin的,有什么办法可以在vaadin flow上做到这一点?

html string text label vaadin
1个回答
0
投票

标签不是用于目标的正确元素。如其API中所述:

请注意,Label组件并非用于页面中的散文-应该通过使用setFor(Component)或通过使用HasComponents.add(Component ...)方法将其添加到另一个组件中来将它们与其他组件耦合。] >

我将改用HTML元素:

        String yourContent ="A new line should be created after this <br /> <b>This text is bold</b> <br /> <i> This text is italic</i>";
        Html html = new Html("<text>" + yourContent + "</text>");
        add(html);

输出:

enter image description here

或者您可以封装功能并创建一个用于显示HTML代码段的常规组件,此处使用示例:https://vaadin.com/forum/thread/17072019

© www.soinside.com 2019 - 2024. All rights reserved.