窗口中显示网页,如何使网页整齐?
下面是我写的简化后的部分程序,在窗口中打开网页,可是网页中内容太乱了,求高手讲解如何设置……谢谢
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);
}
}