
10.10 Graphics Using Swing Components
JScrollPane. HORIZONTAL_SCROLLBAR_ALWAYS);
textArea .setEditable(false); // text area is not editable by user
The actionPerformed method handles action events from the text field as follows:
public void actionPerformed(ActionEvent e) {
String text = textField.getText();
textArea.append(text + newline);
textField.selectAll(); // makes ready for the next entry
}
Observe that the getText() method gets the text entered on pressing the enter key.
It does not get the enter key (new line character). Hence, there is a need to attach the
following.
Example 10.6: Program to demonstrate JTextField class
1. package comm.oops.njchap10; ...