Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 继续回复rtf的帖子(呵呵时间真长)
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2008-07-17 21:50 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
http://www.cjsdn.net/post/view?bid=1&id=82839&tpg=1&ppg=1&sty=1&age=0#82839
浏览网站,看到了4年前的帖子,感慨.....
写了个转换编码方法

public void jButton2_actionPerformed(ActionEvent e)
{
DefaultStyledDocument doc_old = (DefaultStyledDocument)this.jTextPane1.getDocument();


DefaultStyledDocument doc = new DefaultStyledDocument();

Element[] es = doc_old.getRootElements();
for (int i = 0; i < es.length; i++)
{
Element root = es[i];
if (root.getName().equals(DefaultStyledDocument.SectionElementName))
setElement(doc, doc_old, root);

}

this.jTextPane1.setDocument(doc);

}


 
private void setElement(DefaultStyledDocument doc, DefaultStyledDocument doc_old, Element e)
{
try
{
if (e.isLeaf())
{
String text = doc_old.getText(e.getStartOffset(),e.getEndOffset()-e.getStartOffset());
String tempText = new String(text.getBytes("ISO8859-1"), "GBK");

int len = doc.getLength();
doc.insertString(len, tempText, e.getAttributes());
}
else
{
int count = e.getElementCount();
for (int i = 0; i < count; i++)
{
Element ex = e.getElement(i);
setElement(doc, doc_old, ex);
}
}
}
catch (BadLocationException ex1)
{
ex1.printStackTrace();
}
catch (UnsupportedEncodingException ex)
{
/** @todo Handle this exception */
}

}


jameszhang edited on 2008-07-17 22:12

"First they ignore u, then they laugh at u, then they fight u, then u will win

Mahatma Gandhi"


话题树型展开
人气 标题 作者 字数 发贴时间
7973 继续回复rtf的帖子(呵呵时间真长) jameszhang 1757 2008-07-17 21:50

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2018 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923