简体   繁体   English

HTML swing中的html文件浏览

[英]html file browsing in java swing

I am displaying Html file data in Java swing form . 我正在以Java swing形式显示HTML文件数据。 the contents are displaying but some formatting is disturbed . 内容正在显示,但某些格式被打乱。 Images are being displayed but formatting is disturbed . 正在显示图像,但格式化受到干扰。 and hyperlinks are not working can you suggest me the code ,I am using following code . 并且超链接不起作用,您能建议我该代码,我正在使用以下代码。 Is something wrong with setContentType method setContentType方法有问题吗

    File htmlFile = new File("e:/test/help4t.htm");
             htmlPane = new JEditorPane();
            htmlPane.setContentType("text/html");
        htmlPane.setPage(htmlFile.toURI().toURL());
         //URL url= new URL("http://www.lawcrux.com");


       //  htmlPane.setPage(url);
         htmlPane.addHyperlinkListener(this);

        JScrollPane jsp= new JScrollPane(htmlPane);

                cp.add(jsp);
        jsp.setBounds(750, 50, 600, 600);  


        } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "exception is" + ex);
        }

please help 请帮忙

regards 问候

Okay well JEditorPane only supports up to HTML 3.2. 好的, JEditorPane仅支持HTML 3.2。

Even with the above said; 即使以上所说; I would not recoommend rendering html using no library (or your own - unless thats your project) to help you. 我不会建议不使用任何库(或您自己的库,除非是您的项目)来渲染html来帮助您。 Have a look at (pure Java libraries): 看看(纯Java库):

  • The Lobo Project (The Lobo Project aims to develop an extensible browser and RIA platform written completely in Java that not only supports HTML and Javascript, but also enables rendering of arbitrary Rich Internet Application (RIA) languages) Lobo项目 (Lobo项目旨在开发完全用Java编写的可扩展浏览器和RIA平台,该平台不仅支持HTML和Javascript,而且还可以呈现任意的Rich Internet Application(RIA)语言)

  • Ekit (Ekit is a free open source Java HTML editor applet and application. The Ekit standalone also allows for HTML to be loaded and saved, as well as serialized and saved as an RTF. It is approaching its first production release version.) Ekit (Ekit是一个免费的开放源代码Java HTML编辑器小应用程序和应用程序。Ekit独立版本还允许加载和保存HTML,以及将其序列化并保存为RTF。它正在接近其第一个正式发布版本。)

  • The DJ Project (The NativeSwing library allows an easy integration of some native components into Swing applications, and provides some native utilities to enhance Swing's APIs. It is composed of a framework library, and an SWT-based implementation that provides many rich components. The key components of this SWT-based implementation are of course a rich Web Browser and a Flash player, though it also offers a Multimedia Player, an HTML Editor and a Syntax Highlighter.) DJ项目 (NativeSwing库允许将某些本机组件轻松集成到Swing应用程序中,并提供一些本机实用程序来增强Swing的API。它由框架库和基于SWT的实现组成,该实现提供了许多丰富的组件。这个基于SWT的实现的关键组件当然是富Web浏览器和Flash播放器,尽管它还提供了多媒体播放器,HTML编辑器和语法突出显示工具。)

  • CSSBox (CSSBox is an (X)HTML/CSS rendering engine written in pure Java. Its primary purpose is to provide a complete and further processable information about the rendered page contents and layout. However, it also allows displaying the rendered document.) CSSBox (CSSBox是用纯Java编写的(X)HTML / CSS渲染引擎。其主要目的是提供有关渲染的页面内容和布局的完整且可处理的信息。但是,它也允许显示渲染的文档。)

  • RealObjects (not free though) RealObjects (虽然不是免费的)

Why don't you use Jsoup for it provides a very convenient API for extracting and manipulating data. 为什么不使用Jsoup因为它提供了非常方便的API来提取和处理数据。

See this link: 看到这个链接:

http://jsoup.org/ http://jsoup.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM