> i want to resize the jtextfield dynamically as you are typing so that there are no whitespaces on the textfield
Silly requirement:
a) when there is no text the text field will be invisible so the user won't know where to type
b) for a really long string the text field will grow larger than the frame
Use a DocumentListener. Use the getFontMetrics() method and then you can get the width of the text in the text field and then resize it.
a) when there is no text the text field will be invisible so the user won't know where to type
b) for a really long string the text field will grow larger than the frame
That's assuming of course that (a) you don't set a minimum size for it and (b) you have no upper limit either and you're managing to implement it in some oddball heavyweight kind of way.
I think (assume) what the OP wants to do is have a field which starts off as one line, with width behaving as normal, but will wrap and grow vertically to two lines, then three etc as the text grows, shrinking back again as appropriate. You'd want an upper limit to the number of rows it would display before showing a scrollbar.
It's certainly possible using JTextArea - the Jide toolkit has such a widget - but I personally think it's an ill-advised piece of UI since it jiggles everything else around for no real reason. The coding is non-trivial, so unless you know what you're doing and you can justfiy the nastiness of the self-resizing UI then I would suggest you're better off just displaying a three or four rows and using a scroll pane...