title: Trigger event while typing in a JTextComponent java
body: <p>I have a <code>Settings</code> class that should provide interface for retrieving settings and saving them to a file. My settings are supposed to update whenever I change input values (rather than after clicking Save button). This is why I added this method to <code>Settings</code> class:</p>
  
  <pre><code>  /** Automatically update setting value as user types.
     * @param setting_name What is the name of associated setting?
     * @param input JTextComponent (like JTextField) to listen on for events
     */
    public void listenOnInput(final String setting_name, final JTextComponent input) {
      //Debug output
      System.out.println("Settings[\""+setting_name+"\"] automatically updates on input change.");
      input.addInputMethodListener(new InputMethodListener() {
        @Override
        public void inputMethodTextChanged(InputMethodEvent event) {
          //Set setting to current value
          setSetting(setting_name, input.getText());
        }
        //This method is dummy, I see no use for it
        @Override
        public void caretPositionChanged(InputMethodEvent event) {}
      });
    }
  </code></pre>
  
  <p>It's probably not perfect design, but my application will never have complex settings therefore I don't put so much effort in this task. I use it like this:</p>
  
  <pre><code>    JTextField name = new JTextField();
      Settings settings = new Settings();
      name.setToolTipText("Enter your name");
      contentPane.add(name);
      settings.listenOnInput("user_name", name);
  </code></pre>
  
  <p>My problem is that the code above doesn't work - I can type or press <kbd>Enter</kbd> but the <code>inputMethodTextChanged</code> is never called.</p>
  
  <p>So what's proper method of obtaining the value on update?</p>