Results 1 to 3 of 3
  1. #1
    tbuchwalter is offline Member
    Join Date
    Oct 2011
    Rep Power

    Question JScrollPane and viewport issues

    Hi all,

    I am trying to create a UI that uses GridLayout. As a part of this UI I've created a JTextArea and added it to a JScrollPane. I then add text to the text area through out the program using .append() However, the text area keeps expanding down out of a viewable area. I want the text to scroll upward as new text is added but I can not figure out for the life of me how to make this happen. I've tried several different setting i.e. (setMaximumSize() or setPrefferedSize() but neither seem to work.

    Here is a sample of the code:
    //set text area
    jta_area = new JTextArea();
    jta_area.setFont((Font) Game.f);

    combatScroll = new JScrollPane(jta_area);
    Dimension d = new Dimension(15,15);

    Any help you give can give me is much appreciated


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: JScrollPane and viewport issues

    What if wherever you are appending to the JTextArea, you add a line after this that sets the caret position to the end of the document:

    Java Code:
    jta_area.append("whatever you're adding\n");
    // *** add code below ***
    jta_area.setCaretPosition(jta_area.getText().length()); // to place the caret at end of doc

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

Similar Threads

  1. JScrollPane issues - no autoscroll wished
    By Flo in forum AWT / Swing
    Replies: 3
    Last Post: 08-18-2011, 01:17 PM
  2. Need Help With JScrollPane Please
    By MemorableSmile in forum New To Java
    Replies: 4
    Last Post: 01-31-2011, 02:39 AM
  3. Zoom map in JScrollPane, keep center of viewport
    By knuth in forum New To Java
    Replies: 0
    Last Post: 10-01-2009, 07:45 PM
  4. jscrollpane scroll issues
    By kumar_gemi in forum AWT / Swing
    Replies: 11
    Last Post: 09-30-2009, 08:33 PM
  5. help with JScrollPane
    By tommy in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 07:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts