CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  GUI 设计

窗体中不能完美显示网页的问题~~~~~~求教

楼主hunuliudan(铁血丹心)2005-06-01 00:04:39 在 Java / GUI 设计 提问

使用Java中JEditorPane的setPage方法,可以非常方便的将指定的URL对应的Web也显示出来,其支持的格式包括文本和图像。  
  将会用到的核心代码(API):  
   
  editorPane   =   new   JEditorPane();  
  editorPane.setContentType("text/html;   charset=iso-8859-1");  
  try   {  
  editorPane.setPage(url);  
                  }   catch   (IOException   e)   {  
                          System.err.println("Attempted   to   read   a   bad   URL:   "   +   url);  
                  }  
  可是我这么做以后,显示的网页和我们在浏览器中看到的有很大的不同,很多标签都显示出来了,根本就不是一个我们平时见到的网页。这是为什么呢   ?  
  怎么才能完美的显示网页呢?       麻烦指点!!! 问题点数:20、回复次数:3Top

1 楼mituzhishi(慎独)回复于 2005-06-01 19:06:45 得分 15

import   java.io.*;  
  import   java.net.*;  
  import   java.awt.*;  
  import   java.awt.event.*;  
  import   javax.swing.*;  
  import   javax.swing.event.*;  
  import   javax.swing.text.*;  
  import   javax.swing.text.html.*;  
         
  public   class   JEditorPaneExample   extends   JFrame   implements  
          HyperlinkListener  
  {  
          public   static   void   main(String[]   argv)  
          {  
                  JEditorPaneExample   mainApp   =   new   JEditorPaneExample();  
          }  
           
          public   JEditorPaneExample()  
          {  
                  super("JEditorPaneExample   Example");  
                  setBounds(0,   0,   600,   400);  
                  getContentPane().setLayout(null);  
                  setDefaultCloseOperation(EXIT_ON_CLOSE);  
                                 
                  //   Attempt   to   load   an   'index'   html   page...  
                  try  
                  {  
                          URL   url   =   null;  
                   
                        try  
                          {  
                                  url   =   getClass().getResource("index.html");  
                          }  
                          catch(Exception   e)  
                          {  
                                  System.out.println("Could   not   open   file!");  
                                  url   =   null;  
                          }  
                           
                          if(url   !=   null)  
                          {  
                                  htmlViewer   =   new   JEditorPane(url);  
                                  htmlViewer.setEditable(false);  
                                  htmlViewer.addHyperlinkListener(this);  
                           
                                  scrollpane   =   new   JScrollPane();  
                                  scrollpane.setBounds(10,   10,   570,   350);  
                                  scrollpane.getViewport().add(htmlViewer);  
                          }  
                    }  
                    catch(MalformedURLException   e)  
                    {  
                            System.out.println(e);  
                    }  
                    catch(IOException   e)  
                    {  
                            System.out.println(e);  
                    }  
                     
                  getContentPane().add(scrollpane);  
                   
                  setVisible(true);  
          }  
           
          public   void   hyperlinkUpdate(HyperlinkEvent   e)  
          {  
                  if(e.getEventType()   ==   HyperlinkEvent.EventType.ACTIVATED)  
                  {  
                          if(e   instanceof   HTMLFrameHyperlinkEvent)  
                          {  
                                  ((HTMLDocument)   htmlViewer.getDocument()).processHTML  
                                          FrameHyperlinkEvent((HTMLFrameHyperlinkEvent)   e);  
                          }  
                          else  
                          {  
                                  try  
                                  {  
                                          htmlViewer.setPage(e.getURL());  
                                  }  
                                  catch(IOException   e2)  
                                  {  
                                          System.out.println(e2);  
                                  }  
                          }  
                  }  
          }  
                 
          JEditorPane   htmlViewer;  
          JScrollPane   scrollpane;  
  }  
  Top

2 楼mituzhishi(慎独)回复于 2005-06-01 19:07:29 得分 0

JEditorPane又不是浏览器,  
   
  当然不可能完美显示网页了.Top

3 楼shenyinhong(小草)回复于 2005-06-02 10:40:02 得分 5

mituzhishi(向往未来):你的程序通不过编译啊  
  JEditorPaneExample.java:71:   not   a   statement  
                                  ((HTMLDocument)   htmlViewer.getDocument()).processHTML  
                                  ^  
  D:\JEditorPaneExample.java:71:   ';'   expected  
                                  ((HTMLDocument)   htmlViewer.getDocument()).processHTML  
                                                                                                                                            ^  
  2   errors  
  Top

相关问题

  • 如何在PB的窗体里嵌入显示一个网页?
  • 在线等:如何在窗体里显示网页信息
  • 显示窗体
  • 窗体显示?
  • 显示窗体
  • Outlook Web Access可以在网页上显示自己设计的Outlook窗体吗?
  • Outlook Web Access可以在网页上显示自己设计的Outlook窗体吗?
  • Outlook Web Access可以在网页上显示自己设计的Outlook窗体吗?
  • 网页形式的帮助如何在窗体中点击帮助菜单显示?
  • 如何显示主窗体?

关键词

  • 网页
  • swing
  • html
  • null
  • htmlviewer
  • jeditorpaneexample
  • scrollpane
  • jeditorpane
  • processhtml
  • editorpane

得分解答快速导航

  • 帖主:hunuliudan
  • mituzhishi
  • shenyinhong

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo