Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: How to i load my txt file into jtable?

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to i load my txt file into 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.


    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

    this is the code I have for saving my jtable

    savecontact.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
     
    				JFileChooser filesave = new JFileChooser();
    				FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT File", ".txt", "text");
    				filesave.setFileFilter(filter);
    				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(table.getColumnName(col));
    				                    os.print(": ");
    				                    os.println(table.getValueAt(row, col));
     
    				                }
     
     
     
     
    				            }
    				            os.close();
    				            System.out.println("Done!");
    				        } catch (IOException e1) {
    				            // TODO Auto-generated catch block
    				            e1.printStackTrace();
     
    				    }
    				}
    			}
    		});


    this is my code for my table

    table.setModel(new DefaultTableModel(
     
    				new Object[][] {
    			},
    			new String[] {
    				"First Name", "Last Name", "Phone Number", "Email"
    			}
    		));


    i just try this, but it still doesn't work.

     
    	loadcontact.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				 String line;
    		            data = new Vector();
    		            columns = new Vector();
    		            JFileChooser fileload = new JFileChooser();
     
                	    if (fileload.showOpenDialog(Main.this)==JFileChooser.APPROVE_OPTION)
    		            try {
    		            	    File file = fileload.getSelectedFile();
               	    	        FileInputStream fis = new FileInputStream(file);
     
    		                    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    		                    StringTokenizer st1 = new StringTokenizer(br.readLine(), ":");
    		                    while (st1.hasMoreTokens())
    		                            columns.addElement(st1.nextToken());
    		                    while ((line = br.readLine()) != null) {
    		                            StringTokenizer st2 = new StringTokenizer(line, ":");
    		                            while (st2.hasMoreTokens())
    		                                    data.addElement(st2.nextToken());
    		                    }
    		                    br.close();
    		            } catch (Exception e9) {
    		                    e9.printStackTrace();
    		            }
    		    }
     
    		    public int getRowCount() {
    		            return data.size() / getColumnCount();
    		    }
     
    		    public int getColumnCount() {
    		            return columns.size();
    		    }
     
    		    public Object getValueAt(int rowIndex, int columnIndex) {
    		            return (String) data.elementAt((rowIndex * getColumnCount())
    		                            + columnIndex);
     
     
     
     }
    });


  2. #2
    Junior Member
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how do i load 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.


    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

    this is the code I have for saving my jtable
     
    savecontact.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
     
    				JFileChooser filesave = new JFileChooser();
    				FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT File", ".txt", "text");
    				filesave.setFileFilter(filter);
    				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(table.getColumnName(col));
    				                    os.print(": ");
    				                    os.println(table.getValueAt(row, col));
     
    				                }
     
     
     
     
    				            }
    				            os.close();
    				            System.out.println("Done!");
    				        } catch (IOException e1) {
    				            // TODO Auto-generated catch block
    				            e1.printStackTrace();
     
    				    }
    				}
    			}
    		});


    this is my code for my table

     
    table.setModel(new DefaultTableModel(
     
    				new Object[][] {
    			},
    			new String[] {
    				"First Name", "Last Name", "Phone Number", "Email"
    			}
    		));

    this is my entire code
     
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    import javax.swing.table.TableModel;
    import javax.swing.border.LineBorder;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.HeadlessException;
    import java.awt.Window.Type;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import org.eclipse.wb.swing.FocusTraversalOnArray;
    import java.awt.Component;
    import java.awt.SystemColor;
    import java.text.ParseException;
    import javax.swing.JFormattedTextField;
    import javax.swing.text.MaskFormatter;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.io.*;
    import java.util.ArrayList;
    import java.util.StringTokenizer;
    import java.util.Vector;
     
    import javax.swing.filechooser.FileFilter;
    import javax.swing.filechooser.FileNameExtensionFilter;
     
     
     
     
    public class Main extends JFrame  {
     
    	private JTextField Searchtextfield;
    	private  JTable table;
    	private JTextField Firstnametext;
    	private JTextField lastnametext;
    	private JTextField Phonenumbertext;
    	private JTextField Emailtext;
     
     
     
     
     
    	/**
    	 * Instantiates a new main.
    	 * 
    	 * This program allow you to store information in a table and export out and excel file
    	 * or save as a text file
    	 *
    	 * @throws Exception the exception
    	 */
    	public Main() throws Exception  {
     
     
     
     
     
    		getContentPane().setLayout(null);
    		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    		tabbedPane.setBackground(new Color(189, 183, 107));
    		tabbedPane.setBounds(0, 32, 650, 365);
    		getContentPane().add(tabbedPane);
    		MaskFormatter mf2 = new MaskFormatter("(###) ###-####");
     
    	    // the main panel that hold the search bar and table
    		JPanel MainPanel = new JPanel(); 
    		MainPanel.setBackground(Color.LIGHT_GRAY);
    		tabbedPane.addTab("Main", null, MainPanel, null);
    		MainPanel.setLayout(null);
     
    		// the search text field
    		Searchtextfield = new JTextField(); 
    		Searchtextfield.setBounds(485, 11, 129, 20);
    		MainPanel.add(Searchtextfield);
    		Searchtextfield.setColumns(10);
     
    		// the search label on the main panel
    		JLabel Searchlabel = new JLabel("Seach:"); 
    		Searchlabel.setBounds(443, 14, 46, 14);
    		MainPanel.add(Searchlabel);
     
    		JScrollPane scrollPane = new JScrollPane();
    		scrollPane.setBounds(10, 42, 604, 195);
    		MainPanel.add(scrollPane);
     
    		table = new JTable();
    		table.setBorder(UIManager.getBorder("DesktopIcon.border"));
    		scrollPane.setViewportView(table);
     
    		// the column in the table
    		table.setModel(new DefaultTableModel(
     
    				new Object[][] {
    			},
    			new String[] {
    				"First Name", "Last Name", "Phone Number", "Email"
    			}
    		));
     
     
    		// a panel that hold the first name, last name, phone number and email text field for entering 
    		// information into the table on the main panel 
    		JPanel AddentryPanel = new JPanel();
    		AddentryPanel.setBackground(Color.LIGHT_GRAY);
     
    		// add the entry tab for inputting information
    		tabbedPane.addTab("Add Entry", null, AddentryPanel, null); 
    		// set absolute layout
    		AddentryPanel.setLayout(null);
     
    		// a text field for entering you first name
    		Firstnametext = new JTextField();
     
    		Firstnametext.setBounds(175, 49, 308, 34);
     
    		// add the first name text field to the add entry panel
    		AddentryPanel.add(Firstnametext);
    		Firstnametext.setColumns(10);
     
    		JLabel lblNewLabel = new JLabel("First Name:");
    		lblNewLabel.setForeground(Color.BLUE);
    		lblNewLabel.setBounds(98, 59, 99, 14);
    		AddentryPanel.add(lblNewLabel);
     
    		JLabel Lastnamelabel = new JLabel("Last Name:");
    		Lastnamelabel.setForeground(Color.BLUE);
    		Lastnamelabel.setBounds(98, 104, 110, 14);
    		AddentryPanel.add(Lastnamelabel);
     
    		// a text field for entering you last name
    		lastnametext = new JTextField();
    		lastnametext.setColumns(10);
    		lastnametext.setBounds(175, 94, 308, 34);
     
    		// add the last name to the entry panel
    		AddentryPanel.add(lastnametext);
     
    		// add a formatted text field for you phone number. This field only allow number.
    		Phonenumbertext = new JFormattedTextField(mf2);
    		Phonenumbertext.setColumns(10);
    		Phonenumbertext.setBounds(175, 145, 308, 34);
     
    		// add the formatted text field  to entry panel
    		AddentryPanel.add(Phonenumbertext);
     
    		// a text field for entering you email 
    		Emailtext = new JTextField();
    		Emailtext.setColumns(10);
    		Emailtext.setBounds(175, 190, 308, 34);
     
    		// add the email text field to the add entry panel
    		AddentryPanel.add(Emailtext);
     
    		JLabel Phonenumberlabel = new JLabel("Phone Number:");
    		Phonenumberlabel.setForeground(Color.BLUE);
    		Phonenumberlabel.setBounds(77, 155, 93, 14);
    		AddentryPanel.add(Phonenumberlabel);
     
    		JLabel Email = new JLabel("Email:");
    		Email.setForeground(Color.BLUE);
    		Email.setBounds(126, 200, 54, 14);
    		AddentryPanel.add(Email);
     
    		// a button that add information into the table from the first name, last name, email
    		// and you phone number field.
    		JButton AddEntrybutton = new JButton("Add");
     
    		AddEntrybutton.setForeground(Color.GREEN);
     
    		// add a action listener for add entry button
    		AddEntrybutton.addActionListener(new ActionListener() {
    			/*
    			 * This action listener for entry button will prompt
    			 * you, if you want to add information into the table.
    			 * It also check if all the mandatory field have been filled correctly
    			 * so that it can proceed with the adding. If field has a error it will 
    			 * display a error.
    			 */
     
    			public void actionPerformed(ActionEvent e) {
     
    			// check if the option field are filled and correct before adding.
    				if(Firstnametext.getText().equalsIgnoreCase("")|| Phonenumbertext.getText().equalsIgnoreCase("(   )    -    ")){
    					JOptionPane.showMessageDialog (null, "Make sure the the First Name and Phone Number field are filled"); 
    				}
     
    				// prompt if you are sure you want to add these information into the table
    				else if (JOptionPane.showConfirmDialog(null, "Would you like to add these field to table?", "Request", 
    					    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
    					    == JOptionPane.YES_OPTION)
    					{
     
    					DefaultTableModel dtm = (DefaultTableModel)table.getModel();
     
    					dtm.addRow(new Object[] { Firstnametext.getText(), lastnametext.getText(), Phonenumbertext.getText(), Emailtext.getText()});
    					}
     
     
    			}
    		});
    		AddEntrybutton.setBounds(175, 253, 89, 23);
     
    		// add the add button to the entry panel 
    		AddentryPanel.add(AddEntrybutton);
     
     
    		// a button the is use for clearing the field in the add entry panel
    		JButton ClearButton = new JButton("Clear");
    		ClearButton.setForeground(Color.RED);
    		ClearButton.addActionListener(new ActionListener() {
    			/*
    			 *  prompt you if you want to clear the first name,
    			 *  last name, phone number and email text field.
    			 *  if you select yes the field will be clear.
    			 *  if you select no the field will not be clear.
    			 */
     
    			public void actionPerformed(ActionEvent e) {
    				if (JOptionPane.showConfirmDialog(null, "Are you sure you want to clear the field?", "Request", 
    					    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
    					    == JOptionPane.YES_OPTION)
    					{
    					 Firstnametext.setText("");
    					 lastnametext.setText("");
    					 Phonenumbertext.setText("");
    					 Emailtext.setText("");
     
     
    					}
    					else
    					{
    					 //Go back to normal
    					}
     
    			}
    		});
    		ClearButton.setBounds(394, 253, 89, 23);
     
    		// add the clear button the entry panel
    		AddentryPanel.add(ClearButton);
     
    		// label tell that field is optional and doesn't need to be filled
    		JLabel Optionallabel1 = new JLabel("Optional");
     
    		Optionallabel1.setBounds(493, 200, 54, 14);
    		AddentryPanel.add(Optionallabel1);
     
    		// label tell that field is optional and doesn't need to be filled
    		JLabel Optionallabel2 = new JLabel("Optional");
     
    		Optionallabel2.setBounds(493, 104, 54, 14);
    		AddentryPanel.add(Optionallabel2);
     
    		// label that tell you that this field has to be filled
    		JLabel Mandatorylabel1 = new JLabel("Mandatory");
     
    		Mandatorylabel1.setForeground(Color.RED);
    		Mandatorylabel1.setBounds(493, 155, 79, 14);
    		AddentryPanel.add(Mandatorylabel1);
     
    		// label that tell you that this field has to be filled
    		JLabel Manatorylabel2 = new JLabel("Mandatory");
     
    		Manatorylabel2.setForeground(Color.RED);
    		Manatorylabel2.setBounds(493, 59, 64, 14);
    		AddentryPanel.add(Manatorylabel2);
     
    		// a menu bar for displaying the option to load contact, save contact, 
    		// export contact as excel file and be able to close option
    		JMenuBar menuBar = new JMenuBar();
    		menuBar.setBounds(0, 0, 650, 21);
    		getContentPane().add(menuBar);
     
     
    		JMenu fileoption = new JMenu("File");
     
    		menuBar.add(fileoption);
     
     
    		JMenuItem loadcontact = new JMenuItem("Load Contact");
    		loadcontact.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
     
     
     }
    });
     
     
    		// add load contact file to menu
    		fileoption.add(loadcontact);
     
    		JMenuItem savecontact = new JMenuItem("Save Contact");
    		savecontact.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
     
    				JFileChooser filesave = new JFileChooser();
    				FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT File", ".txt", "text");
    				filesave.setFileFilter(filter);
    				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(table.getColumnName(col));
    				                    os.print(": ");
    				                    os.println(table.getValueAt(row, col));
     
    				                }
     
     
     
     
    				            }
    				            os.close();
    				            System.out.println("Done!");
    				        } catch (IOException e1) {
    				            // TODO Auto-generated catch block
    				            e1.printStackTrace();
     
    				    }
    				}
    			}
    		});
     
     
     
     
     
     
     
    		// add a save contact file to menu
    		fileoption.add(savecontact);
     
    		JMenuItem close = new JMenuItem("Close");
    		close.addActionListener(new ActionListener() {
     
    			/*
    			 * When selected the program will close.
    			 * 
    			 */
    			public void actionPerformed(ActionEvent arg0) {
    				System.exit(0);
    			}
    		});
     
    		final JMenuItem mntmExportAsExcel = new JMenuItem("Export As Excel file");
    		mntmExportAsExcel.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
     
    					try {
    						if(e.getSource() == mntmExportAsExcel){
    						    JFileChooser fc = new JFileChooser();
    						    int option = fc.showSaveDialog(Main.this);
    						    if(option == JFileChooser.APPROVE_OPTION){
    						        String filename = fc.getSelectedFile().getName(); 
    						        String path = fc.getSelectedFile().getParentFile().getPath();
     
    								int len = filename.length();
    								String ext = "";
    								String file = "";
     
    								if(len > 4){
    									ext = filename.substring(len-4, len);
    								}
     
    								if(ext.equals(".xls")){
    									file = path + "\\" + filename; 
    								}else{
    									file = path + "\\" + filename + ".xls"; 
    								}
    							toExcel(table, new File(file));
    						    }
    						}
    					} catch (Exception z) {
    						z.printStackTrace();
    					}
     
    			}
    		});
    		fileoption.add(mntmExportAsExcel);
    		fileoption.add(close);
    		table.getColumnModel().getColumn(2).setPreferredWidth(124);
     
    	}
     
     
    	public void toExcel(JTable table, File file){
    	    try{
    	        TableModel model = table.getModel();
    	        FileWriter excel = new FileWriter(file);
     
    	        for(int i = 0; i < model.getColumnCount(); i++){
    	            excel.write(model.getColumnName(i) + "\t");
    	        }
     
    	        excel.write("\n");
     
    	        for(int i=0; i< model.getRowCount(); i++) {
    	            for(int j=0; j < model.getColumnCount(); j++) {
    	                excel.write(model.getValueAt(i,j).toString()+"\t");
    	            }
    	            excel.write("\n");
    	        }
     
    	        excel.close();
     
    	    }catch(IOException e){ System.out.println(e); }
    	}
     
     
     
     
    public static void main(String[] args) throws Exception {
    		Main frame = new Main();
    		frame.setTitle("Phone Book App");
    		frame.setSize(640, 400);
    		frame.setLocationRelativeTo(null); // Center the frame
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
     
    	}
     
     
     
    }


    --- Update ---

    i try this code and it still doesn't work.


    loadcontact.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				 String line;
    		            data = new Vector();
    		            columns = new Vector();
    		            JFileChooser fileload = new JFileChooser();
     
                	    if (fileload.showOpenDialog(Main.this)==JFileChooser.APPROVE_OPTION)
    		            try {
    		            	    File file = fileload.getSelectedFile();
               	    	        FileInputStream fis = new FileInputStream(file);
     
    		                    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    		                    StringTokenizer st1 = new StringTokenizer(br.readLine(), "");
    		                    while (st1.hasMoreTokens())
    		                            columns.addElement(st1.nextToken());
    		                    while ((line = br.readLine()) != null) {
    		                            StringTokenizer st2 = new StringTokenizer(line, ":");
    		                            while (st2.hasMoreTokens())
    		                                    data.addElement(st2.nextToken());
    		                    }
    		                    br.close();
    		            } catch (Exception e9) {
    		                    e9.printStackTrace();
    		            }
    		    }
     
    			public String getColumnName(int i){
    			    return (String)columns.get(i);
    			}
     
    		    public int getRowCount() {
    		            return data.size() / getColumnCount();
    		    }
     
    		    public int getColumnCount() {
    		            return columns.size();
    		    }
     
    		    public Object getValueAt(int rowIndex, int columnIndex) {
    		            return (String) data.elementAt((rowIndex * getColumnCount())
    		                            + columnIndex);
     
     
     
     }
    });

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: how do i load my text file into my jtable.

    Hi legend101z!

    We are happy to help but we need something more specific to go on. Phrases like "it still doesn't work" does not offer much information.
    What does it do, and what should it do instead?
    Are there any error messages? ...if so copy-paste the full text of the error message with your question and code.
    If you have a guess where the problem may be in the code, use comments in the code to bring attention to the line(s) in question.

  4. #4
    Junior Member
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how do i load my text file into my jtable.

    what im trying to is open a text file that will display it content in jtable.
    i try about everything and i still can't get it to work.

     
    	loadcontact.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
     
    		            JFileChooser fileload = new JFileChooser();
     
                	    if (fileload.showOpenDialog(Main.this)==JFileChooser.APPROVE_OPTION)
    		            try {
    		            	    File file = fileload.getSelectedFile();
               	    	        FileInputStream fis = new FileInputStream(file);
     
     
               	    	        reader = new BufferedReader(new FileReader(file));
     
               	    	     while((line = reader.readLine()) != null) 
               	    	        {
    			              tableModel.addRow(line.split(": ")); 
               	    	        }
               	    	        reader.close();
               	    	     }
               	    	    catch(IOException e10){
               	    	        JOptionPane.showMessageDialog(null, "Buffered Reader issue.");
               	    	    }
     
     
     
     
     }
    });

    im getting these error.

    Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
    at java.util.Vector$Itr.checkForComodification(Unknow n Source)
    at java.util.Vector$Itr.next(Unknown Source)
    at javax.swing.plaf.basic.BasicDirectoryModel$LoadFil esThread.cancelRunnables(Unknown Source)
    at javax.swing.plaf.basic.BasicDirectoryModel$LoadFil esThread.cancelRunnables(Unknown Source)
    at javax.swing.plaf.basic.BasicDirectoryModel.validat eFileCache(Unknown Source)
    at sun.swing.FilePane.rescanCurrentDirectory(Unknown Source)
    at javax.swing.plaf.metal.MetalFileChooserUI.rescanCu rrentDirectory(Unknown Source)
    at javax.swing.JFileChooser.rescanCurrentDirectory(Un known Source)
    at javax.swing.JFileChooser.showDialog(Unknown Source)
    at javax.swing.JFileChooser.showOpenDialog(Unknown Source)
    at Main$3.actionPerformed(Main.java:290)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unk nown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mou seReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: How to i load my txt file into jtable?

    Do you understand what java.util.ConcurrentModificationException is telling you?
    Look at some documentation.
    If you can not find the cause of the exception please post again

  6. #6
    Junior Member
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to i load my txt file into jtable?

     tableModel.addRow(line.split(": "));
    this line seem to be the problem.

    --- Update ---

    Quote Originally Posted by jps View Post
    Do you understand what java.util.ConcurrentModificationException is telling you?
    Look at some documentation.
    If you can not find the cause of the exception please post again
    ok it seem like i was able to solve my problem but now i have another issue. When i load my file , it load but it doesn't load into the table properly.

    Update: Here's what I'm seeing.


    Here's what I want.


  7. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: How to i load my txt file into jtable?

    Your First Name column is getting the text "First Name" from your text file (I assume, have not looked at the code).
    If you do not want that part of the text displayed you will have to do something to remove it or ignore it.
    If the text file can live without "First Name" in the first place even better.
    What part of the code decides which incoming text goes to which column/row? Look at the code there and try to see why only First Name and Last Name are being filled in.

  8. #8
    Junior Member
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to i load my txt file into jtable?

    Quote Originally Posted by jps View Post
    Your First Name column is getting the text "First Name" from your text file (I assume, have not looked at the code).
    If you do not want that part of the text displayed you will have to do something to remove it or ignore it.
    If the text file can live without "First Name" in the first place even better.
    What part of the code decides which incoming text goes to which column/row? Look at the code there and try to see why only First Name and Last Name are being filled in.

    I have solved this problem

  9. #9
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: How to i load my txt file into jtable?

    Quote Originally Posted by legend101z View Post
    I have solved this problem
    Please mark the thread as solved when you have solved the problem.
    Under Thread Tools near the top of the page if you do not know where it is.

Similar Threads

  1. Remove JTable row that read txt file records
    By sajjad4563 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 30th, 2012, 01:22 PM
  2. Replies: 0
    Last Post: November 13th, 2012, 06:02 AM
  3. Data from .txt to JTable?
    By skywire_ in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: September 19th, 2011, 04:00 AM
  4. insert(embed) a file object (.txt file) in MS excel sheet using java.
    By jyoti.dce in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 12th, 2010, 08:16 AM
  5. Inputing file (.txt) and finding the highest number in the file
    By alf in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 15th, 2010, 09:11 AM