Java Swing JTextarea 兼容word或者html问题
公司有需求,于是寻找各式资料,文档。最终得出一下结论,
从目前来看,无法兼容word或者html。
所以需要转换方式,swing中的label组件是可以显示html的,可以利用这一点。
解决方案:将html下载配置文件中,然后加载到JLabel中,进行显示。
参考写法:
private Properties prop = new Properties();
static{
InputStream is = ClassLoader.getSystemResourceAsStream("html.properties");
prop.load(is);
}
String text = prop.getProperties(key);
new JLabel(text);
//====================================================
html.properties配置文件中这样写:
key="<html>...</html>"

本文介绍了一种在Java Swing的JTextArea组件中兼容HTML内容的方法。由于JTextArea本身不支持HTML,文章提供了一个替代方案,即通过JLabel组件来实现HTML内容的显示。具体做法是将HTML内容保存在配置文件中,然后加载到JLabel组件上进行展示。
7万+

被折叠的 条评论
为什么被折叠?



