JTextArea不具有显示HTML文本的功能。
用JTextPane吧:~)

解决方案 »

  1.   

    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.IOException;public class TestTextPane extends JFrame {
    private JTextPane textPane = new JTextPane(); public TestTextPane() {
    Container contentPane = getContentPane();
    String url = "http://expert.csdn.net/Expert/topic/3020/3020050.xml?temp=.2243463"; try { 
    textPane.setPage(url);
    }
    catch(IOException ex) { ex.printStackTrace(); } contentPane.add(new JScrollPane(textPane), 
    BorderLayout.CENTER); textPane.setEditable(false); textPane.addHyperlinkListener(new HyperlinkListener() {
    public void hyperlinkUpdate(HyperlinkEvent e) {
    try { 
    textPane.setPage(e.getURL());
    }
    catch(IOException ex) { ex.printStackTrace(); }
    }
    });
    }
    public static void main(String args[]) {
    GJApp.launch(new TestTextPane(), 
    "JTextPane",300,300,450,300);
    }
    }
    class GJApp extends WindowAdapter {
    static private JPanel statusArea = new JPanel();
    static private JLabel status = new JLabel(" ");
    static private ResourceBundle resources; public static void launch(final JFrame f, String title,
      final int x, final int y, 
      final int w, int h) {
    launch(f,title,x,y,w,h,null);
    }
    public static void launch(final JFrame f, String title,
      final int x, final int y, 
      final int w, int h,
      String propertiesFilename) {
    f.setTitle(title);
    f.setBounds(x,y,w,h);
    f.setVisible(true); statusArea.setBorder(BorderFactory.createEtchedBorder());
    statusArea.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
    statusArea.add(status);
    status.setHorizontalAlignment(JLabel.LEFT); f.setDefaultCloseOperation(
    WindowConstants.DISPOSE_ON_CLOSE); if(propertiesFilename != null) {
    resources = ResourceBundle.getBundle(
    propertiesFilename, Locale.getDefault());
    } f.addWindowListener(new WindowAdapter() {
    public void windowClosed(WindowEvent e) {
    System.exit(0);
    }
    });
    }
    static public JPanel getStatusArea() {
    return statusArea;
    }
    static public void showStatus(String s) {
    status.setText(s);
    }
    static Object getResource(String key) {
    if(resources != null) {
    return resources.getString(key);
    }
    return null;
    }
    }
      

  2.   

    显示的是:
    <?xml version="1.0" encoding="GB2312"?>
    <?xml-stylesheet type='text/xsl' href='/expert/Xsl/2.xsl'?>
    <Topic>
    <Issue>
    <PostUserNickName></PostUserNickName>
    <rank>一级(初级)</rank>
    <ranknum>user1</ranknum>
    <credit>       100</credit>
    <TopicId>   3020050</TopicId>
    <TopicName>请问如何让我的JTextArea可以显示html格式的内容</TopicName>
    <PostUserId>623872</PostUserId>
    <PostUserName>wowonan</PostUserName>
    <RoomName>Java J2SE / 基础类</RoomName>
    <ReplyNum>4</ReplyNum>
    <PostDateTime>2004-04-29 10:04:24</PostDateTime>
    <Point>20</Point>
    <ReadNum>0</ReadNum>
    <RoomId>5401</RoomId>
    <EndState>0</EndState>
    <Content>如题,可以说的详细一点吗?谢谢啦</Content>
    </Issue>
    <Replys>
    <Reply><PostUserNickName>marvy</PostUserNickName><rank>一级(初级)</rank><ranknum>user1</ranknum><credit>99</credit><ReplyID>21251374</ReplyID><TopicID>3020050</TopicID><PostUserId>419982</PostUserId><PostUserName>marvy</PostUserName><Point>0</Point><Content>JTextArea不具有显示HTML文本的功能。
    用JTextPane吧:~)</Content><PostDateTime>2004-05-03 14:20:00</PostDateTime></Reply><Reply><PostUserNickName>marvy</PostUserNickName><rank>一级(初级)</rank><ranknum>user1</ranknum><credit>99</credit><ReplyID>21251433</ReplyID><TopicID>3020050</TopicID><PostUserId>419982</PostUserId><PostUserName>marvy</PostUserName><Point>0</Point><Content>import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.IOException;public class TestTextPane extends JFrame {
    private JTextPane textPane = new JTextPane(); public TestTextPane() {
    Container contentPane = getContentPane();
    String url = "http://expert.csdn.net/Expert/topic/3020/3020050.xml?temp=.2243463"; try { 
    textPane.setPage(url);
    }
    catch(IOException ex) { ex.printStackTrace(); } contentPane.add(new JScrollPane(textPane), 
    BorderLayout.CENTER); textPane.setEditable(false); textPane.addHyperlinkListener(new HyperlinkListener() {
    public void hyperlinkUpdate(HyperlinkEvent e) {
    try { 
    textPane.setPage(e.getURL());
    }
    catch(IOException ex) { ex.printStackTrace(); }
    }
    });
    }
    public static void main(String args[]) {
    GJApp.launch(new TestTextPane(), 
    "JTextPane",300,300,450,300);
    }
    }
    class GJApp extends WindowAdapter {
    static private JPanel statusArea = new JPanel();
    static private JLabel status = new JLabel(" ");
    static private ResourceBundle resources; public static void launch(final JFrame f, String title,
      final int x, final int y, 
      final int w, int h) {
    launch(f,title,x,y,w,h,null);
    }
    public static void launch(final JFrame f, String title,
      final int x, final int y, 
      final int w, int h,
      String propertiesFilename) {
    f.setTitle(title);
    f.setBounds(x,y,w,h);
    f.setVisible(true); statusArea.setBorder(BorderFactory.createEtchedBorder());
    statusArea.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
    statusArea.add(status);
    status.setHorizontalAlignment(JLabel.LEFT); f.setDefaultCloseOperation(
    WindowConstants.DISPOSE_ON_CLOSE); if(propertiesFilename != null) {
    resources = ResourceBundle.getBundle(
    propertiesFilename, Locale.getDefault());
    } f.addWindowListener(new WindowAdapter() {
    public void windowClosed(WindowEvent e) {
    System.exit(0);
    }
    });
    }
    static public JPanel getStatusArea() {
    return statusArea;
    }
    static public void showStatus(String s) {
    status.setText(s);
    }
    static Object getResource(String key) {
    if(resources != null) {
    return resources.getString(key);
    }
    return null;
    }
    }
    </Content><PostDateTime>2004-05-03 14:25:00</PostDateTime></Reply><Reply><PostUserNickName></PostUserNickName><rank>一级(初级)</rank><ranknum>user1</ranknum><credit>100</credit><ReplyID>21392394</ReplyID><TopicID>3020050</TopicID><PostUserId>623872</PostUserId><PostUserName>wowonan</PostUserName><Point>0</Point><Content>楼上的大哥,我试了你的代码,还是不能显示啊</Content><PostDateTime>2004-05-10 10:45:00</PostDateTime></Reply><Reply><PostUserNickName>marvy</PostUserNickName><rank>二级(初级)</rank><ranknum>user2</ranknum><credit>99</credit><ReplyID>21393811</ReplyID><TopicID>3020050</TopicID><PostUserId>419982</PostUserId><PostUserName>marvy</PostUserName><Point>0</Point><Content>???
    显示的什么?</Content><PostDateTime>2004-05-10 11:31:00</PostDateTime></Reply></Replys>
    </Topic>