problem with JScrollPane and JTextArea scrolling
824702Dec 18 2010 — edited Dec 23 2010I use a BorderLayout. In this I have added a JScrollPane to BorderLayout.EAST. The JScrollPane has a JTextArea in it.
The width of the JTextArea depends on how long the text length is. The height is the size of the JFrame height. The problem is that I want to set a width of 300 and the height should be same height as the JFrame.
So I write like this
JTextArea area = new JTextArea();
JScrollPane pane = new JScrollPane(area);
How do I set the width on the JTextArea? There is no Width, there is setColumns, and that will not work when I have a JScrollPane around it.
If I set new JTextArea(300, 50); well then the scroll have a height of 50. If I write getWidth() from JFrame, the scrolling function wont work proper when text exceeds this height.
So I have no Idea how i can just set a fixed width and have the height of the textarea grow by itself when text is being added. If I set any size the scrollpane is messedup and scrolls only to this fixed amount.
The only way is that I have to update the height each time I add something in the textarea, check the size and resize it to the new size. Then the scroll will work all the way down. If not, the scroll scrolls down to the height first been given.
Need some light on this. Can anyone help?