首页 > 解决方案 > JTextField 正在锁定输入

问题描述

我正在使用 JTextField (xInput) 输入 x 坐标:

xInput.getDocument().addDocumentListener(new DocumentListener() {
          public void changedUpdate(DocumentEvent e) {
                updateX();
              }
              public void removeUpdate(DocumentEvent e) {
                updateX();
              }
              public void insertUpdate(DocumentEvent e) {
                updateX();
              }

              public void updateX() {
                  try {
                      x = Integer.parseInt(xInput.getText().trim());
                  } catch (NumberFormatException nfe) {
                      if (xInput.getText().equals("")) {
                          x = 0;
                      }
                  }
              }
            });

还有它的 y 对应物,尽管它们是相同的(除了它显然使用 y )并且有相同的问题。

运行程序后会发生什么 - 它使用机器人进行点击 - 当您尝试再次编辑文本字段时,这些字段被锁定,您可以单击或键入它们。我没有在任何地方使用 setEditable。这可能是什么原因造成的?

标签: javaswingjtextfield

解决方案


推荐阅读