当前位置: 代码迷 >> Java相关 >> 窗口中显示网页,如何使网页整齐?
  详细解决方案

窗口中显示网页,如何使网页整齐?

热度:295   发布时间:2013-05-22 20:56:20.0
窗口中显示网页,如何使网页整齐?
下面是我写的简化后的部分程序,在窗口中打开网页,可是网页中内容太乱了,
求高手讲解如何设置……谢谢

import java.io.IOException;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.HTMLDocument;
import javax.swing.text.HTMLFrameHyperlinkEvent;

/**
*
*2013.5.22
*
*/
public class MainFrame extends Frame{

    /**
     * 主窗口程序
     */
    public MainFrame(){
        super("WebOnHook");
        setBounds(150,100,600,400);
        setResizable(true);
        addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
            
        });
        JScrollPane jsp=new JScrollPane();
        add(jsp);
        JViewport jv=jsp.getViewport();
        JEditorPane jep=new JEditorPane();
        jep.addHyperlinkListener(new HyperlinkListener(){
            public void hyperlinkUpdate(HyperlinkEvent e) {
                if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED){
                    JEditorPane pane=(JEditorPane)e.getSource();
                    if(e instanceof HTMLFrameHyperlinkEvent){
                        HTMLFrameHyperlinkEvent evt=(HTMLFrameHyperlinkEvent)e;
                        HTMLDocument doc=(HTMLDocument)pane.getDocument();
                        doc.processHTMLFrameHyperlinkEvent(evt);
                    }else{
                        try{
                            pane.setPage(e.getURL());
                        }catch(Throwable t){
                            t.printStackTrace();
                        }
                    }
                }
            }
            
        });
        jep.setEditable(false);
        try {
            jep.setPage("http://www.baidu.com");
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        jv.add(jep);
    }
   
    public static void main(String[] args) {
        MainFrame mf=new MainFrame();
        mf.setVisible(true);
    }

}
搜索更多相关的解决方案: public  import  super  

----------------解决方案--------------------------------------------------------
好像是构建HTMLDecument.HTMLReader的子类然后重写getReader()方法,但实际怎么写完全不明白,望走过路过的大大们给个实例。

----------------解决方案--------------------------------------------------------
  相关解决方案