File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes automatic scrool to the Textarea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "automatic scrool to the Textarea" Watch "automatic scrool to the Textarea" New topic
Author

automatic scrool to the Textarea

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hello all!
we have a JPanel that is inside a JScrollPane.
In this panel we have different components and in particular we have a JTextArea. if we use the method setText the scrollBar move automaticly to this textArea.
Can someone explain me why this append and how can i avoid this!
thanks in advance.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
If you don't find another way, you could try creating the JTextArea using a custom Document model. I am not sure how complex it is to develop your own Document implementation but if this "feature" is a priority, the J2SE source code could be the place to start from...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Dorothy Finkel-Laverty
Ranch Hand

Joined: Nov 24, 2001
Posts: 51
I tried to duplicate what you are describing, but I am puzzled. I don't get the scroll bars at all unless I actually type into the JTextArea. If I use setText for the JTextArea, it expands the size of the box. When I type in it, it then adds the scroll bars, but around the entire panel, not just the JTextArea.
Can you post your code?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
For the code is not easy to give because several "panel" classes are use together in the mainpanel that contains the scrollbar.

But we find a way to avoid the problem we add a scrollpane just around the text area so the scrollBar that adjust if needed is the one around the scrollpane.
it seems that the default behavour is that when you setText. The textArea try to find in the parent container the first scrollpane to focus on the added text
Dorothy Finkel-Laverty
Ranch Hand

Joined: Nov 24, 2001
Posts: 51
It seems that you'd want the scroll bars around the JTextArea anyhow, right? I know what you mean about it being difficult to post the code - these things get so entangled with the rest of the application that it is difficult to separate them out sometimes.
Glad you found a solution.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
exactly !
thanks to you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: automatic scrool to the Textarea
 
Similar Threads
Dynamically setting TextArea size
Text Fields and Text Areas of Web Page Have Hard Coded Colors
maximum characters in a textarea
Want to display non editable in a frame
trouble with textarea