JTextField and JTextArea
For compatibility with TextField, when the user hits “enter”, the JTextField fires an ActionEvent which can use the methods getText and setText to access the JTextField.
However, the JTextComponents have additional DocumentEvents. When text has changed, one of the following three methods from the Document Interface is called: void insertUpdate ( DocumentEvent e ) void removeUpdate ( DocumentEvent e ) void changedUpdate (DocumentEvent e )
The JTextComponent class has methods to select text by highlighting it and to get selected text.
Note that JTextArea must be put in a scroll pane to have scroll bars.