This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 14364 - Possibility to add DocumentListener to JTextField
Summary: Possibility to add DocumentListener to JTextField
Status: NEW
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 3.x
Hardware: PC Linux
: P3 blocker with 6 votes (vote)
Assignee: issues@guibuilder
: 26399 40690 75089 (view as bug list)
Depends on:
Reported: 2001-08-11 13:46 UTC by Jan Lahoda
Modified: 2011-10-26 22:03 UTC (History)
2 users (show)

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description Jan Lahoda 2001-08-11 13:46:43 UTC
Changes in JTextField should be observed by DocumentListener on it's document
[code looks like:
jTextField.getDocument().addDocumentListener(new DocumentListener() {
I have to write this into code generator by hand (NB3.2.1, build 77), but I
would like to form do it for me.
Comment 1 Tomas Pavek 2001-11-15 17:02:39 UTC
This is not possible. Form Editor can handle only events of the 
components (beans) themselves, not for their property values (even if 
they are beans too). See also issue 8089.
Comment 2 Tomas Pavek 2002-08-09 09:28:55 UTC
*** Issue 26399 has been marked as a duplicate of this issue. ***
Comment 3 matteo porta 2002-08-13 23:19:20 UTC
jbuilder has solved this by allowing its form editor to 
expose the Document in a similar manner to other beans 
beloging to the form. you must do manually for every 
component: select a bean, like jtextfield, then locate its 
document property, then right click and choose "expose as 
class level variable", now in the treeview in the "other" 
section you find the document for the bean. click once on 
it and you see the events like insertUpdate)
i don't understand why you cannot do a similar thing in 
i'm starting to think that the gui builder is a low 
priority module, but please note that the gui builder is 
fundamental if we want java to spread on the desktop.
Comment 4 Tomas Pavek 2002-08-19 10:03:23 UTC
Okay, presented this way it can be taken as reasonable enhancement.
Comment 5 brotherjohn1234 2008-10-25 21:43:10 UTC
JBuilder is no longer realy around the living - but this feature is still not supported under netbeans.
Blame swing, but this would be really a useful feature/hack for NetBeans7 ....

Comment 6 Tomas Pavek 2010-06-07 16:46:52 UTC
*** Bug 40690 has been marked as a duplicate of this bug. ***
Comment 7 Tomas Pavek 2010-06-07 16:46:59 UTC
*** Bug 75089 has been marked as a duplicate of this bug. ***
Comment 8 mikato 2011-10-25 20:07:39 UTC
I came across this bug when trying to figure out how to add a document listener to a jTextField so that I can detect changes without an enter key press.  I couldn't figure it out.  So I guess it's not possible within NetBeans GUI builder.  But I'll just go with focus lost instead rather than something like keypress events.

Here's an example of real-time textfield checking using DocumentListener in the second example on this page -
Comment 9 Tomas Pavek 2011-10-26 16:44:02 UTC
I'd just like to clarify that even without GUI builder support it's pretty easy to add a document listener in the code. Just switch to the source and e.g. in the constructor just after the call of initComponents() you can write something like:

        jTextField1.getDocument().addDocumentListener(new DocumentListener() {
            public void insertUpdate(DocumentEvent e) {
            public void removeUpdate(DocumentEvent e) {
            public void changedUpdate(DocumentEvent e) {

Where 'jTextField1' is the component added using the GUI builder. There's no need to enter some custom code in the GUI builder to be generated by it.
Comment 10 mikato 2011-10-26 22:03:08 UTC
Thanks for that Tomas.  So it's not in initComponents() where it probably should be but that could work.