views:

421

answers:

1

I have a standalone application in which I have a Jtable. In my table, when I type the text, the height of the Textarea should increase dynamically with the text. How can I do this? Can someone help me with an example how to do this?

Thanking You Chaithanya

+1  A: 

It wasn't clear from your question - are you using a JTextArea or a TextArea? The reason it's ambiguous is people generally don't mix and match the light and heavy-weight frameworks (e.g. put awt components within a swing component).

If it's a JTextArea, I think your best bet is probably to use a DocumentListener.

DocumentListener myListener = ??;
JTextArea myArea = ??;
myArea.getDocument().addDocumentListener(myListener);

http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#doclisteners

I think what you'll need to do is listen for changes, and whenever something is added to the file, call the getLineCount() method, and compare it with the getRows() method. If it's broken the threshold, then use a setRows() call to increase the number of rows.

Will probably need to file some sort of UI change, especially to propagate up to the JTable.

I82Much
If you meant TextArea, it doesn't look like the TextArea API provides you with a way of querying how many lines there are currently in the TextArea.If that's the case, you might be better off using a JTextArea (which I would recommend regardless) and use the strategy I outlined above.
I82Much