Results 1 to 7 of 7
  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    245
    Rep Power
    8

    Default Automatically scroll JTextArea as appended

    I have just completed a program completely apart from this one minor thing. Once this is done, so is the program!

    I have a JTextArea that is appended
    Java Code:
    TEXTAREA.append())
    frequently. This JTextArea is inside a JScrollPane and is not editable.

    I want it to always be scrolled to the bottom so that each appendage is automatically visible without user interaction.

    The most common solution I have seen is to adjust the caret to always be at the end of the string of text. However, as I have said, the text area is not editable and thus does not have a caret. Any idea on how to do this with a non-editable text area?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Automatically scroll JTextArea as appended

    Why can't you programmatically set the caret with setCaretPosition()? Or does that have no effect in an uneditable JTextArea?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    245
    Rep Power
    8

    Default Re: Automatically scroll JTextArea as appended

    No effect as there is no caret when uneditable

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Automatically scroll JTextArea as appended

    I know you can programmatically position the scroll bar. What happens if you position it to the extent of the ScrollPane?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    245
    Rep Power
    8

    Default Re: Automatically scroll JTextArea as appended

    Quote Originally Posted by jim829 View Post
    I know you can programmatically position the scroll bar. What happens if you position it to the extent of the ScrollPane?

    Regards,
    Jim
    I don't know how to do this, sorry :(
    Can you guide me in the right direction please?

  6. #6
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    245
    Rep Power
    8

    Default Re: Automatically scroll JTextArea as appended

    I decided to give the caret method another shot and it worked this time. I must have entered it slightly wrong the other times I tried it. Sorry

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    12

Similar Threads

  1. Replies: 3
    Last Post: 01-17-2014, 12:17 PM
  2. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 07:51 PM
  3. Replies: 1
    Last Post: 10-13-2008, 12:42 PM
  4. Replies: 1
    Last Post: 08-07-2007, 05:13 AM
  5. Jtextarea and scroll
    By ziniestro in forum AWT / Swing
    Replies: 2
    Last Post: 06-01-2007, 03:59 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
  •