Results 1 to 4 of 4
  1. #1
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default JTextArea adjustment

    I've created a JTextArea and I'm able to move it to a new location. Code is something like this:
    Java Code:
    		textArea = new JTextArea(45, 35);
    		textArea.setEditable(false);
    		scrollPane = new JScrollPane(textArea);
    		mainPanel.add(scrollPane);
    		scrollPane.setLocation(775,BORDER);
    		textArea.setBackground(Color.GRAY);
    		scrollPane.f
    textArea/scrollPane are defined above this section. Everything works just fine except when the text I'm adding to the textArea gets to the bottom of the textArea and forces a Scroll Bar, it doesn't automatically scroll down to see the newest text. What am I missing? How can I force this to auto scroll down.

    Thanks

  2. #2
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default

    Found this out on the INTERWEBS:

    textArea.setCaretPosition(textArea.getDocument().g etLength());

    Sets the cursor position to the bottom of the new appended text. In conclusion auto scrolls down each time new text is appended.

    Sorry for posting without doing enough research but for those who may stumble upon this problem yourself give this a shot.

  3. #3
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Yep, that's exactly what I encountered on first actual use, how do ( code ) detect caret.notVisible() without wasting resources?
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,304
    Rep Power
    20

    Default

    And if you wish to avoid the default scrolling, or need greater flexibilty check out Rob Camick's blog posts.
    Text Area Scrolling Java Tips Weblog
    Text Utilities Java Tips Weblog

    db

Similar Threads

  1. JTextArea Animation
    By hoglu in forum New To Java
    Replies: 1
    Last Post: 12-18-2008, 11:44 AM
  2. How to manipulate JtextArea
    By bachtoutou in forum New To Java
    Replies: 8
    Last Post: 05-22-2008, 09:36 AM
  3. JTextArea setting
    By newtojava7 in forum New To Java
    Replies: 1
    Last Post: 01-29-2008, 02:57 AM
  4. How to add a shortcut key from JTextArea
    By sukatoa in forum Advanced Java
    Replies: 2
    Last Post: 01-28-2008, 08:39 AM
  5. JTextArea
    By saytri in forum New To Java
    Replies: 0
    Last Post: 01-13-2008, 01:07 AM

Posting Permissions

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