2

I have a HTML code and I want to view in jeditorpane as web page but I could not it.

html code : http://pastebin.com/S0TEGrH5

my attempt:

jEditorPane2.setContentType("text/html");

jEditorPane2.setText(htmlcode);

After this process I have only sound like that dıtt and screen is empty.If I save this code as file (file.html) and jeditorpane2.setpage("file.html") Process have succeed .But I don't want to create file Please give an advise to view html code as web page only use code , no creating file )

2 Answers 2

1

your problem is related to charset.

before the setText you should added this code :

jEditorPane2.getDocument().putProperty("IgnoreCharsetDirective", Boolean.TRUE);
Sign up to request clarification or add additional context in comments.

Comments

0

from: http://mrbool.com/display-html-contents-with-java/24532

import javax.swing.JEditorPane;
import javax.swing.JFrame;

public class HtmlContent extends JFrame {
    public static void main(String args[]) {
        new HtmlContent().start();
    }

    void start() {
        try {
            String html;
            html = "<html><head><title>Simple Page</title></head>";
            html += "<body bgcolor='#777779'><hr/><font size=50>This is Html cont    ent</font><hr/>";
            html += "</body></html>";
            JEditorPane ed1 = new JEditorPane("text/html", html);
            add(ed1);
            setVisible(true);
            setSize(600, 600);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Some problem has occured" + e.getMessage());
        }
    }
}    

1 Comment

Melit, I thought what you did is that you saved your html in the file but dont want to save it. @dooart isnt saving anything to any file, isn't this exactly what you want?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.