JTextField输入限制的定义
JTextField textStart=new JTextField(3);我限制输入的是3列。。为什么我能一直输入数据,而不是我定义的3列?
也就是说当我输入3列后这个文本就不允许我们再输入数据。。那要怎么定义才行
The integer argument passed to thetextField = new JTextField(20);
textField.addActionListener(this);
JTextField
constructor,
20
in the example,
indicates the number of columns in the field.
This number is used along with metrics provided by
the field's current font
to calculate the field's preferred width.
It does not limit the number of characters the user
can enter.
To do that, you can either use a
formatted text field
or a
document listener,
as described in
Text Component Features.