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

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

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

        <i id='fkUOE'><tr id='fkUOE'><dt id='fkUOE'><q id='fkUOE'><span id='fkUOE'><b id='fkUOE'><form id='fkUOE'><ins id='fkUOE'></ins><ul id='fkUOE'></ul><sub id='fkUOE'></sub></form><legend id='fkUOE'></legend><bdo id='fkUOE'><pre id='fkUOE'><center id='fkUOE'></center></pre></bdo></b><th id='fkUOE'></th></span></q></dt></tr></i><div id='fkUOE'><tfoot id='fkUOE'></tfoot><dl id='fkUOE'><fieldset id='fkUOE'></fieldset></dl></div>
        <tfoot id='fkUOE'></tfoot>
      1. Double 的 JFormattedTextField 仍然需要字符

        时间:2023-09-27

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

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

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

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

                <tfoot id='dmXLD'></tfoot>
                    <tbody id='dmXLD'></tbody>
                  本文介绍了Double 的 JFormattedTextField 仍然需要字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个 JFormattedTextField,用户可以在其中输入价格,我有这个,但如果我输入一个字符,它无论如何都会让我输入.我需要此文本字段仅从键盘读取数字或 , 如果它是字符则忽略.我应该如何更改它才能使其正常工作?

                  I have a JFormattedTextField where the user would input prices, I have this, but if I type a character, it'll let me anyway. I need this text field to only read numbers or , from the keyboard, and ignore if it's a char. How should I change it in order to make it work?

                  JFormattedTextField formattedTextField = new JFormattedTextField();
                          formattedTextField.setBounds(25, 330, 56, 20);
                          contentPanel.add(formattedTextField);
                          formattedTextField.setValue(new Double(10.0));
                  

                  推荐答案

                  需要设置一个Formatter:

                  You need to set a Formatter:

                  NumberFormat f = NumberFormat.getNumberInstance(); 
                  JFormattedTextField field = new JFormattedTextField(f);
                  

                  看一下:
                  格式

                  NumberFormat

                  然后试试这个:

                  PlainDocument doc = new PlainDocument();
                  doc.setDocumentFilter(new DocumentFilter() {
                      @Override
                      public void insertString(FilterBypass fb, int off, String str, AttributeSet attr) 
                          throws BadLocationException 
                      {
                          fb.insertString(off, str.replaceAll("\D++", ""), attr);  // remove non-digits
                      } 
                      @Override
                      public void replace(FilterBypass fb, int off, int len, String str, AttributeSet attr) 
                          throws BadLocationException 
                      {
                          fb.replace(off, len, str.replaceAll("\D++", ""), attr);  // remove non-digits
                      }
                  });
                  
                  JFormattedTextField field = new JFormattedTextField();
                  field.setDocument(doc);
                  

                  这篇关于Double 的 JFormattedTextField 仍然需要字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我的布局键盘上的空格按钮大小不会调整大小 下一篇:Android - 获取键盘按键

                  相关文章

                  最新文章

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

                  <small id='6aiMu'></small><noframes id='6aiMu'>

                • <legend id='6aiMu'><style id='6aiMu'><dir id='6aiMu'><q id='6aiMu'></q></dir></style></legend>
                  1. <tfoot id='6aiMu'></tfoot>

                    • <bdo id='6aiMu'></bdo><ul id='6aiMu'></ul>