Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6878649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:45:00+00:00 2026-05-27T04:45:00+00:00

I need to do this: Value Change Listener to JTextField I’m trying the solution

  • 0

I need to do this: Value Change Listener to JTextField

I’m trying the solution of Condemwnci, but I’m getting that error in the line:
textField.getDocument().addDocumentListener(new DocumentListener()
that in my case is:
jtxtfBuscarInv.getDocument().addDocumentListener(new DocumentListener()

In my case I want update rows in a Jtable, so my method will be this:
ordenador.setRowFilter(RowFilter.regexFilter(jtxtfBuscarInv.getText(), 0));

I’m on linux, ubuntu 11.10, using Eclipse if that matters.


Edit:

I don’t understand why, but it works in next way:

textField.getDocument().addDocumentListener(this);

and then overrride the implements methods, instead of doing all in the same lines.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:45:00+00:00Added an answer on May 27, 2026 at 4:45 am

    The two approaches to adding a DocumentListener should be effectively identical. The example below lists all the listeners of type DocumentListener.class for each event. The obvious one is DocumentListeners itself, while the anonymous inner class has the (implementation dependent) name DocumentListeners$1. Both implement the DocumentListener interface. The others are part of typical text component maintenance. Note that two copies are shown, one from each listener added.

    Console:

    javax.swing.text.JTextComponent$InputMethodRequestsHandler@5090d8ea
    DocumentListeners$1@559113f8
    DocumentListeners[,0,0,128x38,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
    javax.swing.plaf.basic.BasicTextUI$UpdateHandler@27b62aab
    javax.swing.text.DefaultCaret$Handler@28ab54eb
    
    javax.swing.text.JTextComponent$InputMethodRequestsHandler@5090d8ea
    DocumentListeners$1@559113f8
    DocumentListeners[,0,0,128x38,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
    javax.swing.plaf.basic.BasicTextUI$UpdateHandler@27b62aab
    javax.swing.text.DefaultCaret$Handler@28ab54eb
    

    Code:

    import java.awt.EventQueue;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.event.DocumentEvent;
    import javax.swing.event.DocumentListener;
    import javax.swing.text.AbstractDocument;
    
    /** @see http://stackoverflow.com/questions/8283067 */
    public class DocumentListeners extends JPanel implements DocumentListener {
    
        JTextField jtf = new JTextField("StackOverflow!");
    
        public DocumentListeners() {
            this.add(jtf);
            jtf.getDocument().addDocumentListener(this);
            jtf.getDocument().addDocumentListener(new DocumentListener() {
    
                @Override
                public void insertUpdate(DocumentEvent e) {
                    print(e);
                }
    
                @Override
                public void removeUpdate(DocumentEvent e) {
                    print(e);
                }
    
                @Override
                public void changedUpdate(DocumentEvent e) {
                    print(e);
                }
            });
        }
    
        private void print(DocumentEvent e) {
            AbstractDocument ad = (AbstractDocument) jtf.getDocument();
            for (DocumentListener dl : ad.getListeners(DocumentListener.class)) {
                System.out.println(dl);
            }
        }
    
        @Override
        public void insertUpdate(DocumentEvent e) {
            print(e);
        }
    
        @Override
        public void removeUpdate(DocumentEvent e) {
            print(e);
        }
    
        @Override
        public void changedUpdate(DocumentEvent e) {
            print(e);
        }
    
        private void display() {
            JFrame f = new JFrame("DocumentListeners");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(this);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new DocumentListeners().display();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get a value from another page. But I get this error
MSDN docs say that only value types need boxing, but this does not apply
I need to this at runtime. I checked using Reflector and value types line
The value of ig is being transfered fine, but I need to put this
there is one variable var=581 we need to copy the value of this variable
I need to add default value column in SqlServer Compact....i am new to this
i need to return a JSON with this format: {answers: [{id: 93, value:Ahstron}, {id=94,
For example i have this xml. I need to get value of parameter val
I created web part (something like wizard) and need change item value in list,
I need know how change Choose a value... in controlType: CategoryFilter of ControlWrapper Example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.