JTextArea text=new JTextArea () Text.setlinewrap (TRUE);//Set the line wrap, then do not need to set the horizontal scroll bar jscrollpane scroll=new JScrollPane ( text);//Set horizontal and vertical scroll bars to appear automatically scroll.sethorizontalscrollbarpolicy (jscrollpane.horizontal_scrollbar_as_needed) respectively; Scroll.setverticalscrollbarpolicy (jscrollpane.vertical_scrollbar_as_needed); setting horizontal and vertical scrollbars, respectively, always appears Scroll.sethorizontalscrollbarpolicy (jscrollpane.horizontal_scrollbar_always); Scroll.setverticalscrollbarpolicy (jscrollpane.vertical_scrollbar_always); setting horizontal and vertical scrollbars, respectively, always hides Scroll.sethorizontalscrollbarpolicy (jscrollpane.horizontal_scrollbar_never); Scroll.setverticalscrollbarpolicy (Jscrollpane.vertical_scrollbar_never); Container Container=mynote.getcontentpane (); Container.add (Scroll,borderlayout.east); Note: Add the scrollbar scoll to the form without adding the scoll textarea, otherwise the myframe.add (scroll) will not be displayed;
Get textarea last last line focus
JTextArea textarea = new JTextArea ();
Textarea.append ("DFASFSADFASFD");
Textarea.setcaretposition (Textarea.gettext (). Length ());
Java Swing TextArea scroll bar and get focus