Loading my text file into my jtable
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Loading my text file into my jtable

  1. #1
    Join Date
    Apr 2013

    Loading my text file into my jtable

    Ok i was able to figure out how to save the data in my jtable as text file but im not sure how i suppose to load it.
    I've been trying to figure this out for few day now and i still lost on how to go about it.

    this is the code I have for saving my jtable
    when i save my code the output in the text file look like this:

    First Name: dan
    Last Name: ram
    Phone Number: (342) 423-4324
    Email: email@live.com

    savecontact.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				JFileChooser filesave = new JFileChooser();
    				FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT File", ".txt", "text");
    				int returnVal = filesave.showSaveDialog(Main.this);
    				    if (returnVal == JFileChooser.APPROVE_OPTION) {
    				        try {
    				        	File file = filesave.getSelectedFile();
    				            PrintWriter os = new PrintWriter(file +".txt");
    				            for (int row = 0; row < table.getRowCount(); row++) {
    				                for (int col = 0; col < table.getColumnCount(); col++) {
    				                    os.print(": ");
    				                    os.println(table.getValueAt(row, col));
    				        } catch (IOException e1) {
    				            // TODO Auto-generated catch block

    this is my table
    table.setModel(new DefaultTableModel(
    				new Object[][] {
    			new String[] {
    				"First Name", "Last Name", "Phone Number", "Email"

  2. #2
    Join Date
    May 2006

    Re: Loading my text file into my jtable

    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a Codeguru.com survey!

HTML5 Development Center