tags:

views:

1108

answers:

3

Hello,

I have a small (500kb) swing applet that displays very simple/limited set of small HTML page(s) inside it with JEditorPane, however this does not seem to work 100% fluently, some customers get a blank page displayed without any java exceptions. The page works OK from my machine. I need a more reliable way to show HTML page to all our users.

Any ideas if there is a small + free class to use instead of JEditorPane OR is there an easy fix to make it more reliable (non blank)

private JEditorPane m_editorPane = new JTextPane();


    m_editorPane.setEditable( false);

    m_editorPane.setBackground(new Color(239  ,255, 215));
    m_editorPane.setBounds(30,42,520,478 );
    m_editorPane.setDoubleBuffered(true);
    m_editorPane.setBorder(null);

    m_editorPane.registerEditorKitForContentType("text/html", "com.xxxxx.SynchronousHTMLEditorKit");


m_editorPane.setPage(ResourceLoader.getURLforDataFile(param.trim()));
+1  A: 

AFAIK, JEditorPane is a very primitive HTML component: it is confused by CSS and knows nothing about JS.
I doubt you will find a "small + free" class doing better, HTML parsing and displaying isn't a simple business, even less today.

Perhaps it is better to let the big names in the business to take care of this task, ie. using Internet Explorer or Mozilla components (depending on what is available, etc.): JDIC: Embedding a Web browser in Java.

PhiLho
well, I am displaying very basic html (text and 1-2 pictures), and its important for me that component is a small one, works with all browsers and OSes. So I am afraid this embedding option is not ok.
Tom
I missed the fact you display your own pages. I would look why it works on some machines and not on others. Do they have the same system? The same JRE?
PhiLho
they have standard Win + JRE 1.5 but indeed a pretty strict firefall , could it be somekind of firewall/security limitation.. would it help to sign the applet..?
Tom
If the applet tries to access external resources (local or on a different Web server than the applet's one), indeed it must be signed. And well, it doesn't hurt to try! :-)
PhiLho
+1  A: 

Although I haven't used it before, Lobo is an open source web browser for Java with support for HTML 4, Javascript and CSS 2.

Compared to the JEditorPane which only has support of HTML 3.2, it seems like Lobo may be a better bet for loading modern web pages.

coobird
thanks, but I dont need modern HTML 4, just basic Html and easy way to show a few pages.
Tom
A: 

I've recently POC-ed several java HTML rendering solutions. We decided on JEditorPane because we really need to minimize the size of our jar and it's built into Swing. However, the best library I came across was Flying Saucer. It doesn't have any js support but it's rendering quality and api is top notch, and it's "free" (LGLP), 100% Java, and only about 1mb (still too big for us, but small compared to other options). However, it only renders strict XHTML (all attribute values have to be quoted, all tags properly formed), but that may be OK depending on your needs (and HtmlCleaner or some other such utility may help towards that end).

Stephen Swensen