如何更改jtexfield的监听器? [英] how add a listener for jtexfield when it changing?

查看:213
本文介绍了如何更改jtexfield的监听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 JTextField。我想在其中的文本发生变化时调用一个函数。

I have a JTextField. I want to invoke a function when the text in it is changed.

我该怎么做?

推荐答案

Java中适当的监听器用于跟踪JTextField文本内容的变化是DocumentListener ,你必须添加到JTextField的文档:

The appropriate listener in Java's swing to track changes in the text content of a JTextField is a DocumentListener, that you have to add to the document of the JTextField:

myTextField.getDocument().addDocumentListener(new DocumentListener() {
    // implement the methods
});

这篇关于如何更改jtexfield的监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆