I am trying to have the DocListener check to see if a JTextField is empty and if it is empty to hide a button, id the textfield is not empty the button will appear
here is the coed that I have for the DocListener. I already added the DocListener to the textfield tfName. When the Code runs the button is still visible??? Am I writing the Listener wrong or am I adding it to the textfield wrong??

```
MyDocumentListener d1 = new MyDocumentListener();
tfName.getDocument().addDocumentListener(d1);

private class MyDocumentListener implements DocumentListener
{
    @Override
    public void changedUpdate(DocumentEvent e) {
        // TODO Auto-generated method stub  
    }
    @Override
    public void insertUpdate(DocumentEvent e) 
        { //is used when the user types anything into the textfield
            if(tfName.getText().trim().length() == 0)
                btnSubmit.setEnabled(false);
            else
                btnSubmit.setEnabled(true);
        }
    @Override
    public void removeUpdate(DocumentEvent e) 
    { //is used when the user uses backspace in the textfield
        if(tfName.getText().trim().length() == 0)

            btnSubmit.setEnabled(false);
        else
            btnSubmit.setEnabled(true);
    }
}

```