Results 1 to 9 of 9
  1. #1
    Mulligan is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default Saving contents of textarea

    Hi. I am new here.

    I have written a programme that calculates figures in textfields then displays them in a textarea. I was wondering if there is anyway to save the figures and text in the textarea. I know it would come under the ioexception and printerscanner. I was just wondering if there is an easy way to do it as the data is in the textarea, rather than having to write every entry that was previously in the textboxes into the ioexception.

    Is there any examples of code any of you could provide or any suggestions to do this easily.

    Thank you.

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Java Code:
    myTextArea.getText();
    JTextArea (Java Platform SE 6)
    -> JTextComponent (Java Platform SE 6)
    --> JTextComponent.getText() (Java Platform SE 6)

    Reading the Api's are often helpful. It you look JTextArea inherits methods from JTextComponent, JTextComponent has a getText() method which returns a String containing the information in the JTextComponent. In this case, your JTextArea.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    write every entry that was previously in the textboxes into the ioexception
    This is a strange task.
    What is a "ioexception"? How do write into it?

  4. #4
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    I think he meant IO to a file, or something similar.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  5. #5
    Mulligan is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Dark View Post
    I think he meant IO to a file, or something similar.
    Yep that is what I meant. I have already used the get.text function to get the figures from the individual textfields then displayed in the textarea. I want to save the conglomerated figures to the harddrive in a file format then reopen them again. I was wondering whether there is an easy way to this by getting the text from the textarea rather than the individual textfields. Then saving it to a file I can reopen.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,335
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Dark View Post
    Java Code:
    myTextArea.getText();
    JTextArea (Java Platform SE 6)
    -> JTextComponent (Java Platform SE 6)
    --> JTextComponent.getText() (Java Platform SE 6)

    Reading the Api's are often helpful. It you look JTextArea inherits methods from JTextComponent, JTextComponent has a getText() method which returns a String containing the information in the JTextComponent. In this case, your JTextArea.
    A JtextArea inherits a write(Writer w) method from its parent class; I'd suggest you'd use that method instead of the getText() method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Yes there is, are you familiar with java.io (Java Platform SE 6) ?

    Try taking a look at BufferedWriter (Java Platform SE 6)

    I did something similar by using a BufferedWriter connected to a FileWriter and simply used
    Java Code:
    myBufferedWriter.write(myTextArea.getText());
    However I'm still fairly new to this, and JosAH's suggestion may work better. I would have to look into the proper syntax of his method to help you further.
    Last edited by Dark; 07-06-2011 at 09:00 PM.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    First take a look at how the file output methods work. For a text file, you will be writing the output line by line.
    A line being a String followed by the newline character.

  9. #9
    Mulligan is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    Wow thank you for all your help. This is a wonderful start.

    I will have to do some research then get back to you.

Similar Threads

  1. Saving the contents of a variable to disk
    By ckannan90 in forum New To Java
    Replies: 2
    Last Post: 08-11-2010, 10:37 PM
  2. Replies: 1
    Last Post: 02-23-2010, 09:48 AM
  3. Replies: 3
    Last Post: 12-03-2009, 10:05 PM
  4. Replies: 1
    Last Post: 10-29-2008, 07:01 PM
  5. TextArea Bug?
    By Soda in forum New To Java
    Replies: 2
    Last Post: 12-07-2007, 12:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •