There is such code:
public class Main { public static void main(String[] args) { JFrame frame = new JFrame(); JTextField t = new JTextField(); frame.add(BorderLayout.NORTH, t); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true); t.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String s = t.getText(); } }); } } ActionListener monitors JTextField and transfers data only after pressing Enter .
The program has several JTextField fields. How to make the text read, even if the user does not press Enter every time?
Or how to make a form to fill in differently (with data entry fields and a submit button)? By type as it is done in HTML:
<form> <input type="text"> <input type="text"> <input type="submit"> </form>
textField.getDocument().addDocumentListener(new DocumentListener()just catch these changes. Didn’t consider this option? - Senior Pomidor