views:

54

answers:

3
+1  A: 

you need to specify:

textArea.setColumns (160);
textArea.setLineWrap (true);
textArea.setWrapStyleWord (false); //default

But the real problem is that you allow to input more than 160 characters. You need to create some kind of validator which will skip all inputed characters when there are already 160 characters written.

Roman
+1  A: 

Sound like you are creating the text area using

JTextArea textArea = new JTextArea();

When using this format the text area doesn't have a preferred size so it keeps on growing. If you use:

JTextArea textArea = new JTextArea(2, 30);
JScrollPane = new JScrollPane( textArea );

Then the text area will have a preferred size of 2 rows and (roughly) 30 columns. As you type when you exceed the preferred width the horizontal scrollbar will appear. Or if you turn on wrapping, then the text will wrap and a vertical scrollbar will appear.

camickr
A: 

Initialise the textArea with a document that extends PlainDocument and in the insertString method limit the characters to 160

Calm Storm
-1, This has nothing to do with controlling the size of the text area, only the number of characters that can be added to the Document. Also, the user has already written a DocumentFilter to do this, which is the preferred approach to limit the number of characters.
camickr