?? 什么意思? 是让 JPanel 显示 html 代码吗?
还是像浏览器一样“翻译”html语句显示文字、画面……

解决方案 »

  1.   

    使用JEditorPane可以直接显示html。
    你再把JEditorPane组件直接加入到JPanel内,就可以了。
      

  2.   

    用javax.swing.JTextPane 或者它的父类javax.swing.JEditorPane 
    可以当作一个简单的浏览器不过对于稍微复杂一点的html 显示格式和IE有很大区别
      

  3.   

    JDK例程里好像有个专门的HtmlPane,我忘了具体的类名了,应该比较好找
      

  4.   

    像浏览器一样“翻译”html语句显示文字、画面……
      

  5.   

    我还是不明白,是不是jEditorPane.setText("...html代码..."),这样就能显示出我想要的(和IE中显示一样)文字或画面了?
      

  6.   

    我还是不明白,是不是jEditorPane.setText("...html代码..."),这样就能显示出我想要的(和IE中显示一样)文字或画面了?
      

  7.   

    import javax.swing.*;
    import java.awt.*;
    public class TestHtml
    {
        public TestHtml()
        {
        }
        public static JComponent getPanel()
        {
            String html="<body><table><tr><td><input type='text' size=2'/></td></tr></body>";        JPanel panel = new JPanel(new BorderLayout());
            JEditorPane editorPane = new JEditorPane("text/html",html);
            editorPane.setEditable(false);
            panel.add(editorPane,BorderLayout.CENTER);
            return panel;
        }
        public static void main(String[] args)
        {
            JFrame f = new JFrame();
             f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             f.setSize(300,270);
             f.getContentPane().add( getPanel() );
             Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
             Dimension frameSize = f.getSize();
             f.setBounds((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2,
                            frameSize.width,frameSize.height);
             f.setVisible(true);
        }}