java - Word Wrap in JEditorPane and System Font -


i'm wanting create large text field user type in. want use default system font match , feel expected. tried use jeditorpane default constructor, uses plain text encoding.

jeditorpane editorpane = new jeditorpane(); editorpane.settext(gettysburgaddress); 

enter image description here

the trouble plain text encoding doesn't wrap newline @ end of each word, when runs out of characters.

i tried using html encoding, word wraps:

jeditorpane editorpane = new jeditorpane("text/html", ""); editorpane.settext(gettysburgaddress); 

enter image description here

this has word wrap, defaults different font default system (helvetica on mac os x, don't want.

how can best of both worlds: word wrap , system default font? don't need special formatting or this, plain text encoding if possible.

if needed word-wrapped jeditorpane using system font, , don't need special stylized text or images, it's best switch jtextarea, text component doing plain text. doesn't word wrap default, it's easy make happen:

jtextarea textarea = new jtextarea(); textarea.setlinewrap(true); //makes text wrap next line textarea.setwrapstyleword(true); //makes text wrap full words, not letters textarea.settext(gettysburgaddress); 

if absolutely must use jeditorpane reason, you'll have roll sleeves , make changes way jeditorpane rendering text. on plus side, have several different methods choose from. can:

  • set encoding html (which word wraps) , use css specify font (described here)
  • set encoding rtf (which word wraps) , modify font values of underlying rtfeditorkit (described here)
  • create simpleattributeset , use when adding strings specify should displayed in way (described here)

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -