Updating a text area from a JtextField! HELP
Code :
usernamelabel = new JLabel ("Username: ");
add(usernamelabel);
username = new JTextField ("Guest", 10);
add(username);
Code :
users = new TextArea(username.getText(), 15,20, TextArea.SCROLLBARS_VERTICAL_ONLY);
users.setEditable(false);
add(users);
The TextArea - users Dosent update when i change the Username, can someone help me?
http://prntscr.com/5j7qf <-PICTURE
Re: Updating a text area from a JtextField! HELP
Quote:
users = new TextArea(username.getText(), 15,20, TextArea.SCROLLBARS_VERTICAL_ONLY);
When you use username.getText() in the constructor, the JTextArea's initial text is set to the value currently in the username JTextField. However, nothing in your program is telling users's text to update if username's text is changed. You need to write some code that does that. I suggest looking at a DocumentListener.