• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

help in displaying textfield data in a textarea

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello nice to be on this forum. i am learning Java and i am building an application. i am using netbeans as my IDE. i have a text area ,  text fields  and a button to generate a receipt in the text area when clicked( fill the data  in the text field in the text area so i can print as a receipt. Iwant to to write a code that when the button is clicked, the data in the text field is displayed in the text area and if another data is entered and clicked it will be displayed in the next row. this is the code i have used:
textarea.setText("****************************************************************************\n");
      String fun,fun2;
     fun = textfield.getText();
     fun2 = textfield.getText();
    textarea.setText(textarea.getText()+fun + "\n" +fun+"\n");
    textarea.setText(textarea.getText()+"Item         Dimension               Quantity             Price " );
this code works when a button is click  but when i enter new information it overrides the existing which is not what i want
i need help please
 
Rancher
Posts: 3051
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "setText(...)" method will replace the text in the text area.

You want to use the append(...) method of the text area to add text to the bottom of the text area.
 
clary chis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ROB, it is a step forward. it works but this line of text "Item         Dimension               Quantity             Price " keeps appending too. do you know of a way i can have it appear only once. another iss sue is  i have to have the total display every time at the bottom. but i haven't been able to figure a way. can you help
thanks
 
clary chis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
basically i want to be able to get user input text from text fields, display and print a receipt in the text area and  when the receit is printed, the entries in the data base are updated
thank
 
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only want to put the headings into the text area once, right?

So put the headings in there before you start accepting user input, then append the user inputs as they come in.
 
clary chis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
once more thank you . what about getting the totals from the various columns. do you know how i can do it. i have thought of using arraylist to  store the textfield whenever the user clicks on the button. but i am still brainstorming on it
 
Paul Clapham
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have some variables to store the totals. Set them to zero initially. Every time you get the numbers for the columns, add them to those total variables.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!