java - JEditorPane with HTMLEditorKit returning newline character instead of <br> tag -
i’m trying work around inconsistency when using jeditorpane.gettext() htmleditorkit installed.
i can utilize jeditorpane.settext pass html string containing < br> tags, , when utilize gettext() new-lines appear correctly < br>. when user enters new-line in jeditorpane, gettext() returns “/n” character rather < br> tag. custom html parser can’t distinguish between users “/n” characters , “/n” characters added –seemingly – create html string pretty. example:
if user enters text, jeditorpane.gettext() procedure homecoming this:
<html> <head> </head> <body> i've written text! indeed much text line going word wrap when run gettext procedure! , nail come in few times! wonder happen if wraps time? wham. , i'll nail come in 1 time more measure. </body> </html>
whereas i’d expect show as:
<html> <head> </head> <body> i've written text! indeed much text line going word wrap when run gettext procedure!<br><br>and nail come in few times! wonder happen if wraps time? wham.<br>and i'll nail come in 1 time more measure. </body> </html>
is there way have < br> inserted in gettext string when user hits enter? first effort utilize documentfilter, documentation says i’m aloud utilize insertstring or filterbypass within filter, hence can’t utilize settext (“< br>”) route. after tons of reading, i’m thinking alternative extend htmleditorkit , override read procedure? jtextcomponents new me, that’s way on head. there other options? or resources?
thanks!
you can utilize documentlistener , track \n inserts. on insert create dummy element inserted \n , replace it's outer html (using setouterelement() method of htmldocument).
see illustration of autoreplace smiles here
java jeditorpane documentfilter htmleditorkit
No comments:
Post a Comment