jtcy
asked on
TextField methods help!
I have a textField and a textArea:
TextArea messages = new TextArea(10,50);
TextField message = new TextField(52);
I have an ActionListener here:
message.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEven t e)
{
// Complete message sending action
}
};
What I wanna do is, when the user enter stuff into the textField and press enter, I wan the text to appear in textArea and the textField will be cleared. First, which method of TextField should I use to get the text? And second, how can I clear the field?
TextArea messages = new TextArea(10,50);
TextField message = new TextField(52);
I have an ActionListener here:
message.addActionListener(
{
public void actionPerformed(ActionEven
{
// Complete message sending action
}
};
What I wanna do is, when the user enter stuff into the textField and press enter, I wan the text to appear in textArea and the textField will be cleared. First, which method of TextField should I use to get the text? And second, how can I clear the field?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What do you mean with sentence?
You may append new lines of text to the text already in text area as I've done above with.
tmp += "\r\n" + text;
Note the += !
You may also use append() to add to end of text:
messages.append( message.getText() );
You may append new lines of text to the text already in text area as I've done above with.
tmp += "\r\n" + text;
Note the += !
You may also use append() to add to end of text:
messages.append( message.getText() );
ASKER
Oh thanks, it;s working
ASKER
What about I wanna have a "->" sign in front of the user's own message in messages? Like if the user enter hello, it will apeear as -> hello in the textArea?
JUst add the -> before you appenmd to textarea:
messages.append( "-> " + message.getText() );
messages.append( "-> " + message.getText() );
ASKER
Thanks!
Um...how do i set the scrollbar to hm..sort of automatically scrolling down when there are new messages?? Like....for now, if the text area has been full of messages, the next messages wont appear unless the user scrolls the bar down himself. How can i make the scrollbar scrolls down itself when it is needed? ie. always update the latest messaage at the bottom?
Um...how do i set the scrollbar to hm..sort of automatically scrolling down when there are new messages?? Like....for now, if the text area has been full of messages, the next messages wont appear unless the user scrolls the bar down himself. How can i make the scrollbar scrolls down itself when it is needed? ie. always update the latest messaage at the bottom?
use JTextArea.scrollRectToVisi ble(); ( see JDK doc for details)
And: Please open new question to get more help and to give others a chance.
And: Please open new question to get more help and to give others a chance.
ASKER