The Artima Developer Community
Sponsored Link

Java Answers Forum
How to clear this field

5 replies on 1 page. Most recent reply: Mar 14, 2002 1:07 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Eduardo

Posts: 21
Nickname: eduardo
Registered: Feb, 2002

How to clear this field Posted: Mar 14, 2002 7:36 AM
Reply to this message Reply
Advertisement
Okay... I created the following problem for myself:

if ((evt.getSource() == jmiddleInit) ||
(evt.getSource() == enter))
{
String nameText = jmiddleInit.getText();
lbmiddleInit.setText("Middle initials: " + nameText.toUpperCase());
jmiddleInit.setVisible(false);
}// ends if statement

This is going to read whatever I type in the box and then, after pressing "enter", just converts it to upper case and makes it visible.

But I need to not only clear this field, but make the box available for a new entry.

Does anybody have any suggestion?

Thank you!


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: How to clear this field Posted: Mar 14, 2002 9:06 AM
Reply to this message Reply
use the method

setText("");

with your TextField or TextArea or TextComponent object.

Example:

Textfield textfield = new TextField("My initial String"); //creates a TextField object with an initial string set to "My initial String"

textfield.setText(""); // clears it

Eduardo

Posts: 21
Nickname: eduardo
Registered: Feb, 2002

Re: How to clear this field Posted: Mar 14, 2002 9:51 AM
Reply to this message Reply
Thanks!
Actually, I was forgetting to make it visible again. (O;'

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: How to clear this field Posted: Mar 14, 2002 11:18 AM
Reply to this message Reply
Another common method of dealing with this situation is not to empty out the field, but instead to select all the text in it. That way, if you start typing immediately, you replace the text, but this also allows for you to slightly alter the text without retyping it all, if that is preferred. This is how you would select all the text in a JTextField and also set the focus to that field:
   entryField.selectAll();
   entryField.requestFocus();

Eduardo

Posts: 21
Nickname: eduardo
Registered: Feb, 2002

That was great! Posted: Mar 14, 2002 11:35 AM
Reply to this message Reply
Thank you, guys! I've just tested it Matt... very good!

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: How to clear this field Posted: Mar 14, 2002 1:07 PM
Reply to this message Reply
That was good. I'll use that!

Flat View: This topic has 5 replies on 1 page
Topic: Giving Applet AllPermisions Previous Topic   Next Topic Topic: 1 thing missing in car animation

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use