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.
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...
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?
Joined: Nov 22, 2008
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
Joined: Nov 24, 2001
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.