<legend id='XMlPm'><style id='XMlPm'><dir id='XMlPm'><q id='XMlPm'></q></dir></style></legend>

    1. <small id='XMlPm'></small><noframes id='XMlPm'>

      <tfoot id='XMlPm'></tfoot>

      • <bdo id='XMlPm'></bdo><ul id='XMlPm'></ul>
      <i id='XMlPm'><tr id='XMlPm'><dt id='XMlPm'><q id='XMlPm'><span id='XMlPm'><b id='XMlPm'><form id='XMlPm'><ins id='XMlPm'></ins><ul id='XMlPm'></ul><sub id='XMlPm'></sub></form><legend id='XMlPm'></legend><bdo id='XMlPm'><pre id='XMlPm'><center id='XMlPm'></center></pre></bdo></b><th id='XMlPm'></th></span></q></dt></tr></i><div id='XMlPm'><tfoot id='XMlPm'></tfoot><dl id='XMlPm'><fieldset id='XMlPm'></fieldset></dl></div>

      在 Swing 中可以将 JTextField 配置为只接受数字吗?

      It#39;s possible in Swing configure a JTextField to only accept numbers?(在 Swing 中可以将 JTextField 配置为只接受数字吗?)

    2. <legend id='JTh0J'><style id='JTh0J'><dir id='JTh0J'><q id='JTh0J'></q></dir></style></legend>

      <i id='JTh0J'><tr id='JTh0J'><dt id='JTh0J'><q id='JTh0J'><span id='JTh0J'><b id='JTh0J'><form id='JTh0J'><ins id='JTh0J'></ins><ul id='JTh0J'></ul><sub id='JTh0J'></sub></form><legend id='JTh0J'></legend><bdo id='JTh0J'><pre id='JTh0J'><center id='JTh0J'></center></pre></bdo></b><th id='JTh0J'></th></span></q></dt></tr></i><div id='JTh0J'><tfoot id='JTh0J'></tfoot><dl id='JTh0J'><fieldset id='JTh0J'></fieldset></dl></div>

      <tfoot id='JTh0J'></tfoot>

    3. <small id='JTh0J'></small><noframes id='JTh0J'>

        <tbody id='JTh0J'></tbody>
          <bdo id='JTh0J'></bdo><ul id='JTh0J'></ul>

              1. 本文介绍了在 Swing 中可以将 JTextField 配置为只接受数字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                可能重复:
                有没有办法只接受数字JTextField 中的值?

                Swing 的 JTextField 上是否有任何功能只允许数字范围内的正数?

                There any functionality on the JTextField of Swing that allow only positive numbers inside a range of numbers?

                示例:我只能输入 10 到 30 之间的数字.超出此范围的数字甚至不会出现在字段中.

                Example: I can only enter numbers between 10 and 30. Numbers out of this range will not even appear in the field.

                推荐答案

                使用 JSpinnerSpinnerNumberModel - 最终用户会感谢你的.好吧,不是字面意思,但至少他们不会因为强迫他们使用箭头键输入他们想要选择的内容而诅咒你的名字.

                Use a JSpinner with a SpinnerNumberModel - the end user will thank you. OK not literally, but at least they will not curse your name for forcing them to type in something they'd like to choose using the arrow keys.

                import javax.swing.*;
                
                class NumberChooser {
                
                    public static void main(String[] args) {
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                SpinnerNumberModel numberModel = new SpinnerNumberModel(
                                    new Integer(15), // value
                                    new Integer(10), // min
                                    new Integer(30), // max
                                    new Integer(1) // step
                                    );
                                JSpinner numberChooser = new JSpinner(numberModel);
                                JOptionPane.showMessageDialog(null, numberChooser);
                                System.out.println("Number: " + numberChooser.getValue());
                            }
                        });
                    }
                }
                

                这篇关于在 Swing 中可以将 JTextField 配置为只接受数字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Compiling C++ for the JVM(为 JVM 编译 C++)
                Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)
                <i id='qWfAc'><tr id='qWfAc'><dt id='qWfAc'><q id='qWfAc'><span id='qWfAc'><b id='qWfAc'><form id='qWfAc'><ins id='qWfAc'></ins><ul id='qWfAc'></ul><sub id='qWfAc'></sub></form><legend id='qWfAc'></legend><bdo id='qWfAc'><pre id='qWfAc'><center id='qWfAc'></center></pre></bdo></b><th id='qWfAc'></th></span></q></dt></tr></i><div id='qWfAc'><tfoot id='qWfAc'></tfoot><dl id='qWfAc'><fieldset id='qWfAc'></fieldset></dl></div>

                <small id='qWfAc'></small><noframes id='qWfAc'>

                      <tbody id='qWfAc'></tbody>
                    <tfoot id='qWfAc'></tfoot>
                    <legend id='qWfAc'><style id='qWfAc'><dir id='qWfAc'><q id='qWfAc'></q></dir></style></legend>

                    • <bdo id='qWfAc'></bdo><ul id='qWfAc'></ul>