Reputation: 2535
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 )
Upvotes: 2
Views: 4083
Reputation:
your problem is related to charset.
before the setText you should added this code :
jEditorPane2.getDocument().putProperty("IgnoreCharsetDirective", Boolean.TRUE);
Upvotes: 1
Reputation: 941
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());
}
}
}
Upvotes: 0