New= tp.getstyleddocument (); =int panewidth =new String (BT, 0, Len);
Try { for (int i = 0, cnt = 0, I < text.length (), + +i) { if (cnt + = Fm.charwidth (Text.charat (i))) = panewidth) {//When the character's width is greater than the width of the panel, the line is wrapped, that is, the Jtextpane does not appear horizontal scroll bar cnt = 0; Doc.insertstring (Doc.getlength (), "\ n", set); Continue;} doc.insertstring (Doc.getlength (), string.valueof (Text.charat (i)), set); } doc.insertstring (Doc.getlength (), "\ n", set), Tp.setcaretposition (Doc.getlength ());//The simplest way to set the position of the scrollbar to the last output text place is to move the caret position in the Jtextpane to the end of the text! }
Jtextpane in Java to wrap the output character to a specified width and move the position of the vertical scroll bar to the last position of the output