DocumentEvent « JTextField « Java Swing Q&A





1. JTextField DocumentListener/DocumentEvent    stackoverflow.com

i would like to know how to use a DocumentListener/DocumentEvent in java to prevent the user from deleting a certain portion of text in a JTextField, like on the windows command ...

2. how to find source component that generated a DocumentEvent    stackoverflow.com

Is it possible to discover which oject generated a DocumentEvent? Something like i can do with ActionListener:

JTextField field = new JTextField("");
field.addActionListener(actionListener);

//inside ActionListener
public void actionPerformed(ActionEvent arg0) {
  if (arg0.getSource() instanceof JTextField) ...

3. Get Element name in DocumentEvent    stackoverflow.com

Is it possible to get the root elements name, actionCommand, etc... in DocumentListener. I need to get the JTextField name to keep a track of which textfield was modified.

public void insertUpdate(DocumentEvent ...