How do I read a HTML String into a JEditorPane/JTextPane?
Asked Answered
C

2

6

Pretty self explanatory, I have a string that is HTML, how do i draw this onto a JEditorPane/JTextPane?

Christie answered 20/7, 2012 at 19:32 Comment(2)
What have you tried? I mean besides effectively asking random strangers on the internet to do it for you.Instill
google, rose india, superuser, this, etcChristie
S
16

Do you mean something like this?

JFrame frame=new JFrame();
JEditorPane pane=new JEditorPane();
pane.setContentType("text/html");
String data="<table border=\"1\"><tr><td>cell1</td><td>cell2</td></tr></table>";
pane.setText(data);

frame.add(pane);
frame.setSize(200,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);
Sweetie answered 20/7, 2012 at 19:42 Comment(0)
D
0

You'll need to find an html interpreter if you're trying to put that single string into a pane. However, if you have a separate page that you're dealing with that holds the html, you can use JTextPane's setPage(String URL) function.

Dreadnought answered 20/7, 2012 at 19:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.