I have to get a list of entries from a text file to display in a JFrame. I was able to do that but everything is displaying on one line.
How do I get it to display as it is listed in the text file?
Here is what the text file contains:
Rick Sebastian 49 Rick@home.com 813-111-2222
John Doe 35 John@work.com 813-222-3333
Peggy Bundy 50 Peggy@theoffice.com 813-333-4444
Al Bundy 55 Al@thebar.com 813-444-5555
Jane Doe 27 Jane@thebeach.com 813-555-6666
Here is how it is displayed in the program:
Capture.jpg
Here is the code I'm working with:
package contact.display.info; import java.io.*; import javax.swing.*; /** * * @author Rick Sebastian */ public class ContactDisplayInfo extends JFrame { JTabbedPane jtp1=new JTabbedPane(); JPanel jp1=new JPanel(); JTextArea t1=new JTextArea(); ContactDisplayInfo () throws Exception { super("ContactDisplayinfo"); FileReader f=new FileReader("C:/Users/Me/Documents/ContactInformationProgram/ContactInfo.txt"); BufferedReader brk=new BufferedReader(f); String s; while((s=brk.readLine())!=null){ t1.append(s); } jp1.add(t1); jtp1.addTab("Tab1",t1); add(jtp1); //setSize(400, 400); setLocationRelativeTo(null); } public static void main(String args[]) throws Exception { ContactDisplayInfo cdi=new ContactDisplayInfo(); cdi.pack(); cdi.setVisible(true); cdi.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
I set the frame size to 400 400 and that only changed the size of the frame. The text still extended out in one line. i know I need a word wrap of some sort, but I'm not sure how that's done, or how I would get it to group by individual entry. Ideally I would have 5 lines with 5 entries being displayed.
Any help you can offer would be greatly appreciated!
Rick