• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Erasing existing text

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setText() should work for you. Here's a simple working example.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic