I have a GUI in which there is a TextArea in which I have to display some text.Sometimes the no. of lines of text exceeds the no. of rows of the TextArea.So I thought of adding a JScrollPane.But I am unable to do so.I am new to Java and Swing that is why I am having problems.I tried out many things.I went through the Swing tutorials at - http://java.sun.com/docs/books/tutorial/uiswing/components I am providing relevant portion of my codes below -
In the getJTextArea method,I tried to use the following lines - JScrollPane scrollpane=new JScrollPane(); scrollpane.setViewportView(jTextArea); return jTextArea;
But it is not working.Currently the number of rows in TextArea is 5. Whenever no. of lines of display is exceeding 5,the TextArea is elongating and pushing out the other components out of the window.Please tell me how to add the scrollpane.I read that the scroll bars are added automatically in the text area when necessary.So I do not need to invoke any methods on the JScrollPane object.So the only thing I have to do is to add the scrollpane at the correct position with the correct dimension,which I am not able to do right now.Please correct me if I am wrong.