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

  • <legend id='UVxjO'><style id='UVxjO'><dir id='UVxjO'><q id='UVxjO'></q></dir></style></legend>

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

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

      1. <tfoot id='UVxjO'></tfoot>

        JSpinner 值变化事件

        时间:2023-09-29

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

          <tbody id='TKbcd'></tbody>

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

          <tfoot id='TKbcd'></tfoot>

                1. <legend id='TKbcd'><style id='TKbcd'><dir id='TKbcd'><q id='TKbcd'></q></dir></style></legend>
                2. 本文介绍了JSpinner 值变化事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  当 jSpinner 值改变时如何立即更新.

                  How to make the update immediately when the jSpinner value was changed.

                  ChangeListener listener = new ChangeListener() {
                    public void stateChanged(ChangeEvent e) {
                      jLabel.setText(e.getSource());
                    }
                  };
                  
                  spinner1.addChangeListener(listener);
                  

                  上面的代码不会自动改变标签文本,它需要你在任何地方再次点击才能更新.

                  The code above doesnt change the label text automatically, it required you to click again anyplace to update.

                  推荐答案

                  答案是配置JFormattedTextField中使用的格式化程序,它是微调器的编辑器的子项:

                  The answer is to configure the formatter used in the JFormattedTextField which is a child of the spinner's editor:

                      formatter.setCommitsOnValidEdit(true);
                  

                  不幸的是,得到一个人的手就像介绍句一样又长又脏:

                  Unfortunately, getting one's hand on it is as long and dirty as the introductory sentence:

                      final JSpinner spinner = new JSpinner();
                      JComponent comp = spinner.getEditor();
                      JFormattedTextField field = (JFormattedTextField) comp.getComponent(0);
                      DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
                      formatter.setCommitsOnValidEdit(true);
                      spinner.addChangeListener(new ChangeListener() {
                  
                          @Override
                          public void stateChanged(ChangeEvent e) {
                              LOG.info("value changed: " + spinner.getValue());
                          }
                      });
                  

                  一种稍微(但不是很多)更简洁的方法可能是继承 NumberEditor 并公开一个允许配置的方法

                  A slightly (but not by much) cleaner way might be to subclass NumberEditor and expose a method which allows the config

                  这篇关于JSpinner 值变化事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Java - Swing 中的 mouseMoved() 事件处理 下一篇:JTable:检测单元格数据变化

                  相关文章

                  最新文章

                    <tfoot id='vLLjz'></tfoot>

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

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

                        <bdo id='vLLjz'></bdo><ul id='vLLjz'></ul>