<分区>
<分区>
有没有办法将 css 类添加到 Java 字符串内联?
将类添加到标签:
String siteNameText = "This is : ";
String siteName = "StackOverflow.com";
Label siteNameLabel = new Label(siteNameText + siteName);
siteNameLabel.getStyleClass().add("site_name_bold");
有没有办法只将样式类添加到 siteName
中的 "StackOverflow.com"
?唯一的其他选择是通过将它们放入两个不同的标签来将它们分开。
最佳答案
检查 AttributedString 类,它完全按照您的要求执行。
编辑:但是,您不能直接在 Label/JLabel 中使用它,您需要使用图形对象自己绘制字符串。
关于java - 有没有办法将 css 样式类添加到 Java 字符串内联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31918648/