Limiting the number of characters that can be entered into a JTextField

I haven’t worked with Swing in a while and I can not remember how to limit the number of characters that a user can enter into a JTextField. I looked at sun’s site and all I could find to accomplish this was the InputVerifier class, but I remember this task being a lot simpler. Maybe something like this:

JTextField jtfCustomerPhone = new JTextField();
jtfCustomerPhone.setCharacterLimit(10);

Any help will be greatly appreciated.

your answer is here:
http://javaalmanac.com/egs/javax.swing.text/LimitText.html

Try class NumberFormat!

For example:
NumberFormat N;


public Diagr() {
setLayout(null);
N = NumberFormat.getInstance();
N.setGroupingUsed(false);
N.setMaximumFractionDigits(3);

}