File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Erasing existing text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Erasing existing text" Watch "Erasing existing text" New topic
Author

Erasing existing text

Alisha Burke
Greenhorn

Joined: Jan 22, 2005
Posts: 27
Helloo everyone!!

Anyone out there who knows how to erase existing text with a new one. I don't think i can use something.setText("") or can I???

Basically what i did is : when a user enters 2 numbers or more the program will do the calculation and display the results. However the problem that i am facing now is when i change the numbers to a new one it will continue doing the calculation and display the results but it will add on the answer to the existing one.

I want it to erase the previous answers and display just the latest one.

I have only one button to show the answer(I tried using the ifElse statement but because there is no clear button>>its not really working as it should).

So is there any other way to automatically clear the text in the textarea(output) once the values in the textfields(input)is changed?

And is there a method to make this bold ormake anything italic without using g.setFont in graphics paint. Just curious.

Thanks in advance.
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
Assuming the text you want to change is in a textField you can change the text with setText(). Add a listener to the second/last text entry field and call a method that resets your textField with the new value. Should also be able to use setFont() to make it bold if that's what you want.
Alisha Burke
Greenhorn

Joined: Jan 22, 2005
Posts: 27
Assuming the text you want to change is in a textField you can change the text with setText(). Add a listener to the second/last text entry field and call a method that resets your textField with the new value. Should also be able to use setFont() to make it bold if that's what you want.


Yup yr correct about the setFont actually i've been using it the whole time but there was a bit of confusion there (as i was previously using textField and changed to textArea).....i am trying to get used to using textAreas..

And yes i have tried using setText as you can read in my post, however, its only displaying the last line of my answer....when i use append it tops up the new answer to the old ...and i only want the new answers.
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
setText() should work for you. Here's a simple working example.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Erasing existing text
 
Similar Threads
Need help in SWT Form
Big text file into textarea
random images
populate the form field with the submitted input
How to change text in a image(.gif file) through Java