"
TextFields
One column is the expected width of on e character in the font you are using for the text.. you are supposed
to specify n (number of columns) as the column width.
Users tend to find scrolling text fields irritating, so
you should size the fields generously.
...
After changing the size of a text box with the setColumns method, call the revalidate
method of the surrounding container.
textField.setColumns(10);
panel.revalidate();
The revalidate method recomputes the size and layout of all components in a container.
After you use the revalidate method, the layout manager resizes the container, and the
changed size of the text field will be visible.
The revalidate method belongs to the JComponent class. It doesn’t immediately resize the
component but merely marks it for resizing. This approach avoids repetitive calculations
if multiple components request to be resized.
However, if you want to recompute all
components inside a JFrame, you have to call the validate method—JFrame doesn’t extend
JComponent."
Core
Java Volume 1 (8th Edition) Pg. 378.
Does the author refer to Container.validate() ?
On the other hand, the documentation for JComponent.revalidate() reads as follows:
"revalidate
public void revalidate()
Supports
deferred automatic layout.
Calls invalidate and then adds this component's validateRoot to a list of components that need to be validated. Validation will occur after all currently pending events have been dispatched. In other words after this method is called, the first validateRoot (if any) found when walking up the containment hierarchy of this component will be validated. By default, JRootPane, JScrollPane, and JTextField return true from isValidateRoot.
This method will automatically be called on this component when a property value changes such that size, location, or internal layout of this component has been affected.
This automatic updating differs from the AWT because programs generally no longer need to invoke validate to get the contents of the GUI to update."
Source: Java 1.6 API
I have noticed that leaving the columns property to [0] when using NetBeans GUI to create a
demo seemed to have no effect, since there seems to be a default width for JTextField: