JTextField: How to limit the number of characters?

前端 未结 2 1460
时光说笑
时光说笑 2021-01-12 18:01

Please have a look at the following code.

import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.*;
import javax.swing.text.AbstractDocum         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-12 18:24

    You should make your own class that checks whether you gave more input than the maximum allowed length: See an example on http://www.java2s.com/Tutorial/Java/0240__Swing/LimitJTextFieldinputtoamaximumlength.htm.

提交回复
热议问题