将JTextPane设置为内容类型HTML并使用字符串构建器 [英] setting JTextPane to content type HTML and using string builders

查看:248
本文介绍了将JTextPane设置为内容类型HTML并使用字符串构建器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用字符串构建器将文本附加到我的JTextPane,我已经将内容类型设置为 pane.setContentType(text / html); 文本实际上出现在我的JTextPane上。



这是我的追加示例:

  buildSomething.append(< b style = \color:pink \>+ Birthday +< / span>); 

有什么我正在做的严重错误?我怎样才能解决它?

每次 JTextPane.setText(...)解决方案被称为新的内容类型被确定。使用< html>开始文本并获得HTML。



创建一个新文档,在你的情况HTMLDocument。






@mKorbel:下面每次为JTextPane创建HTML。

  buildSomething.append(< html>); 
buildSomething1.append(< html>);
for(int i = 0; i <10; i ++){
buildSomething.append(< span style = \color:red \>+ myBirthday +< ; /跨度>中);
buildSomething1.append(< b style = \color:blue \>+ myBirthday +< / b>);
}


I'm using string builders to append text to my JTextPane, I've set content type as pane.setContentType("text/html"); but the no text actually appears on my JTextPane.

This is an example of my append:

buildSomething.append("<b style=\"color:pink\">"+Birthday+"</span>");

Is there something I'm doing severely wrong? And how do I go about fixit it?

解决方案

Every time JTextPane.setText(...) is called a new content type is determined. Start the text with "<html>" and you've got HTML.

A new document is created, in your case HTMLDocument.


@mKorbel: the following creates every time HTML for the JTextPane.

    buildSomething.append("<html>");
    buildSomething1.append("<html>");
    for (int i = 0; i < 10; i++) {
        buildSomething.append("<span style=\"color:red\">" + myBirthday + "</span>");
        buildSomething1.append("<b style=\"color:blue\">" + myBirthday + "</b>");
    }

这篇关于将JTextPane设置为内容类型HTML并使用字符串构建器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆