Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JTextField setColumns() does not seem to work, why?

130 views
Skip to first unread message

Mark_Galeck

unread,
Jul 22, 2008, 7:52:28 PM7/22/08
to
Hello, I construct a

JTextField textField = new JTextField(string, string.length()).

Later, I want to change the string to a longer one, by calling

textField.setColumns(longerString.length());
textField.setText(longerString);

This does not work, setColumns has no effect, setText does work, the
string displayed changes but does not fit in the field.


Why? Please explain, thank you. Mark

Mark_Galeck

unread,
Jul 22, 2008, 8:02:57 PM7/22/08
to
Oh, I found the answer myself, sorry for being so dumb. The enclosing
container needs to validate the new layout.

Roedy Green

unread,
Jul 23, 2008, 5:00:38 AM7/23/08
to
On Tue, 22 Jul 2008 16:52:28 -0700 (PDT), Mark_Galeck
<mark_galeck...@yahoo.com> wrote, quoted or indirectly quoted
someone who said :

>This does not work, setColumns has no effect, setText does work, the
>string displayed changes but does not fit in the field.

this means the optimum box size will change. However, it won't be
redrawn until you re-validate.

That number is very approximate since you are not using a fix-pitch
font.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

0 new messages