标题:窗口中显示网页,如何使网页整齐?
只看楼主
KeyWing
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-5-20
 问题点数:0 回复次数:1 
窗口中显示网页,如何使网页整齐?
下面是我写的简化后的部分程序,在窗口中打开网页,可是网页中内容太乱了,
求高手讲解如何设置……谢谢

import
import java.awt.*;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.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 
2013-05-22 20:56
KeyWing
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-5-20
得分:0 
好像是构建HTMLDecument.HTMLReader的子类然后重写getReader()方法,但实际怎么写完全不明白,望走过路过的大大们给个实例。
2013-05-23 19:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-407776-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.952132 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved