i want to transfere the content of the file to the jtextfield as it is in the file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahmed222too
    New Member
    • Sep 2007
    • 47

    i want to transfere the content of the file to the jtextfield as it is in the file

    when i read data from file by code into jtextfield the lines of the file apprear in Concatenation in the jtextfield (without Enters between lines)
    i want to transfere the content of the file to the jtextfield as it is in the file (with Enters between lines)
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by ahmed222too
    when i read data from file by code into jtextfield the lines of the file apprear in Concatenation in the jtextfield (without Enters between lines)
    i want to transfere the content of the file to the jtextfield as it is in the file (with Enters between lines)
    A JTextField is a single line text component; i.e. it can't display more than one
    line of text. Use a JTextArea instead.

    kind regards,

    Jos

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      By the way, this method is a handy way to read data in a text component: Read method

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by BigDaddyLH
        By the way, this method is a handy way to read data in a text component: Read method
        I fell into that trap once: that read method installs a new Document in the
        component. If you had just pooped up your JTextComponent with all sorts
        of listeners and undoable managers etc. they aren't carried over to the new
        Document, i.e. you have to do that yourself after the read has finished.

        kind regards,

        Jos

        Comment

        • Kid Programmer
          New Member
          • Mar 2008
          • 176

          #5
          Originally posted by ahmed222too
          when i read data from file by code into jtextfield the lines of the file apprear in Concatenation in the jtextfield (without Enters between lines)
          i want to transfere the content of the file to the jtextfield as it is in the file (with Enters between lines)
          Listen to the first post by JosAH. Change the code in the imports from:
          Code:
          import javax.swing.JTextField;
          to:
          Code:
          import javax.swing.JTextArea;
          and change the variable declaration to:
          Code:
          jtextarea = new JTextArea("");
          That should do the trick.

          Comment

          Working...