简体   繁体   中英

How do you use DocumentListener with jTextField in Netbeans?

I'm trying to take the value entered in a jTextField, parse it, then use it to calculate an output.

In every other application I've used this is really simple. There is some form of event that will trigger when the text is changed, and I can use that event to perform the actions I want. In netbeans though, no such luck. The closest to an on changed event I could find was InputMethodTextChanged, which doesn't seem to work how I think it does.

Every resource online says to use a documentListener, but no resource that I can find actually gives information on how to use it. I'm sure for an experienced programmer the information provided is more than enough, but an experienced programmer already knows how to use it.

Could somebody please explain how DocumentListener works, and how to use it clearly enough for a novice programmer to understand? Stack Overflow always shows up quickly in Google Searches, and at the moment there is no newbie friendly source of information on this that is easy to find, if at all.

I know the answer comes very late, but for other people who will try to find the answer of this issue, please have a look here: https://netbeans.org/bugzilla/show_bug.cgi?id=14364 . At this moment (NetBeans 8.2) this is still not implemented and the only way is to edit the source code yourself.

jTextField1.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { } }

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM