How to implement in Java ( JTextField
class ) to allow entering only digits?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Add a DocumentFilter to the (Plain)Document used in the JTextField to avoid non-digits.
Use this class, and call it where you need to validation pass your jtexField name as parameter.
Use a
Document
implementation whoseinsertString
method filters out the non-digit characters.Use a
JFormattedTextField
.http://download.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html
Try out this
DocumentFilter
:Usage: