java - Getting raw text from JTextPane -


In my application, I use the JTextPane to display some log information. As I want to lighten certain lines (for example error message) in this lesson, I have set contentType as " text / html ". In this way, I can format my text.

Now, I am creating a pocket button that copies this JTextPane content into the clipboard. This part is easy, but my problem is that when I call myTextPane.getText () , I get the HTML code like this:

  & lt ; Html & gt; & Lt; Top & gt; & Lt; / Head & gt; & Lt; Body & gt; Blabla & lt; Br> & Lt; Font color = "# FFCC 66" & gt; & Lt; B & gt; Fauber & lt; / B & gt; & Lt; / Font & gt; & Lt; Br> Blubber & lt; / Body & gt; & Lt; / Html & gt;  

Instead of just getting raw content:

  Blubal Fobar Blubber  

Is there only one way plain The contents of my jtextpane in the text? Or do I need to change the HTML in raw text by myself?

based on the accepted answer:

  MyHtml2Text parser = New MyHtml2Text (); Try {parser.parse (new stringreader (myTextPane.getText ())); } Hold (IOException EE) {// handle exception} System.out.println (parser.getText ());  

I found a link that was found on the imported code from import java.io.IOException Html2text slightly modified version of the class; Import javax.swing.text.html. *; Import javax.swing.text.html.parser *; Public class MyHtml2Text HTMLEditorKit.ParserCallback {StringBuffer s; Public MyHtml2Text () {} throws public Zero Pars (Reader In) IOException {s = new StringBuffer (); Parsegalator representative = new parsedelier (); Delegator.parse (in, this, boolean. TRUE); } Public Zero Handle Text (four [] text, int pause {s.append (text); S.append ("\ n"); } Public string getText () {return s.toString (); }}

If you need more corrective handling then


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -