resizing jtextfield to wrap string

how do i resize a jtextfield to wrap the string in it?... this does not have to be done dynamically, if it's easier
[123 byte] By [javabingea] at [2007-10-3 2:19:14]
# 1
What do you mean wrap? Like setColumns()?
kirillga at 2007-7-14 19:18:08 > top of Java-index,Desktop,Core GUI APIs...
# 2
If you're talking about wrapping to multiple lines, you can't with a JTextField.You'll need to use a JTextArea or JTextPane.
JayDSa at 2007-7-14 19:18:08 > top of Java-index,Desktop,Core GUI APIs...
# 3
like setColumns.... but the problem with setColumns is that it doesn't necessarily equal the number of characters.... for example if you said txtField.setColumns(20);i could most definitely fit more than 20 i's in there
javabingea at 2007-7-14 19:18:08 > top of Java-index,Desktop,Core GUI APIs...
# 4
Really don't understand your question.If you need wrapping then you use a JTextArea.If you want fixed with character then you need to use a monospaced font. Then "i" and "W" will take the same amount of space and the columns will equal the number of characters on each line.
camickra at 2007-7-14 19:18:08 > top of Java-index,Desktop,Core GUI APIs...
# 5
i want to resize the jtextfield dynamically as you are typing so that there are no whitespaces on the textfield
javabingea at 2007-7-14 19:18:08 > top of Java-index,Desktop,Core GUI APIs...
# 6
> i want to resize the jtextfield dynamically as you> are typing so that there are no whitespaces on the> textfieldYour OP said " this does not have to be done dynamically, if it's easier"Anyway, look at a keylistener.
zadoka at 2007-7-14 19:18:08 > top of Java-index,Desktop,Core GUI APIs...
# 7

> 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.

camickra at 2007-7-14 19:18:08 > top of Java-index,Desktop,Core GUI APIs...
# 8

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...

itchyscratchya at 2007-7-14 19:18:08 > top of Java-index,Desktop,Core GUI APIs...