JTextField内容改变自动触发事件

当你的JTextField内容改变的时候,你想有相应的响应,那你就为它添加一个监听器
            JTextField = new JTextField();
            Document dt = myTextField.getDocument();
            dt.addDocumentListener(new javax.swing.event.DocumentListener(){                  
                public void insertUpdate(DocumentEvent e) {
                    System.out.println("insertUpdate");
                }
               **
                 * 文本内容减少时出发这个方法
                 */    
                public void removeUpdate(DocumentEvent e) {
                    System.out.println("removeUpdate");
                }

                
                public void changedUpdate(DocumentEvent e) {
                    System.out.println("changedUpdate");
                }

                
            });

你可能感兴趣的:(JTextField内容改变自动触发事件)