java - 如何设置 jformattedtextfield 仅采用 2 个值?

标签 java jformattedtextfield

我知道如何设置 jformattedtextfield 以允许用户仅写入数字、字母...但我希望用户只能写入两个值:1 或 0。 我怎样才能做到这一点。我写的是:

MaskFormatter mf6;
    try {
        mf6 = new MaskFormatter("#");
        txtformatted = new javax.swing.JFormattedTextField(mf6);
    } catch (ParseException e) {
        //e.printStackTrace();
    }

最佳答案

i want that a user can write only two values: 1 or 0.

查看 MaskFormatter 类的 setValidCharacters(...) 方法。

关于java - 如何设置 jformattedtextfield 仅采用 2 个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26182088/

相关文章:

java - 项目缺少必需的库 - 但存在正确的 JAR?

java - 什么数组/集合对象对于 "contains"函数最有效?

java - 在 Java 中通过 JFormattedTextFields 进行验证

java - 从文件读取时的system.arraycopy - java

java - Spring HandlerInterceptor 不捕获 GET、POST 以外的方法

java - 从枚举引用创建对象

java - JFormattedTextField 的 setValue 不显示在 GUI 上

Java : Does Locale affect the Formatter for JFormattedTextField

java - 在 Java 的 JFormattedTextfield 中设置数字的上限

java - 将 JFormattedTextField 中的多个值分配给多个变量