Is there any way to accept only numeric values in a JTextField?

前端 未结 19 1922
陌清茗
陌清茗 2020-11-22 03:10

Is there any way to accept only numeric values in a JTextField? Is there any special method for this?

19条回答
  •  太阳男子
    2020-11-22 03:58

    Although there is the pure evil JFormattedTextField there isn't a trivial way to do it using only the Swing library. The best way to implement this sort of feature is with a DocumentFilter.

    Some code I prepared earlier. A bit of description.

提交回复
热议问题