Philip Morris Philip Morris - 1 year ago 73
Java Question

Change Listener for a JTextfield

I made a program that dynamically gets data from a Panel but my code needs the user to hit the enter button for the data to be updated. Is there a change listener or other listeners that can update the data from a Jtextfield whenever it is updated? Thanks!

Answer Source

Just add a listener to the textfield so that it tracks when the text changes

textfieldName.getDocument().addDocumentListener(new DocumentListener() {
    // implement the methods
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download