Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to add text file(.txt) input into JTable?

843805Apr 9 2007 — edited Apr 9 2007
hello,

how to add text file input into jTable .
I have one text file all.txt,
in this I store some IP values one by one.

i need to add the IP values into jTable IP Address column. how can I do it. any example is there.

my code is,
 public void ListDisplay ()
    {
        IPList.setModel(jList2model);  
        try {
             FileInputStream fis = new FileInputStream("Devices/all.txt");
             BufferedReader br = new BufferedReader(new InputStreamReader(fis));
             String line = null;
             Vector data = new Vector();
            line = br.readLine();
           //  while ( (line = br.readLine()) != null) 
           ///  {
                 
                 row.addElement(line);
               //  row.addElement(ipText.getText()+"-"+nameText.getText());
                   row.addElement((String)" ");
                   row.addElement((String) "");
                    row.addElement((String) "");
                    row.addElement((String) "");       
                    row.addElement((String) "");   
                   // tableModel.addRow(row);
                   rows.add(row);
                  nmsTable.addNotify();
                          
                // jList2model.add(jList2model.getSize() ,line);
                 
            // }  
              br.close();
             
             }
             catch (Exception ee) {}
}
I am using the default data model and store the rows and clums in that data model.
 rows=new Vector();
        colNames = new Vector();
        String[] columnNames = {"IP Address","Status"};
        addColumns(columnNames);
        tableModel=new DefaultTableModel(rows,colNames);
        nmsTable.setModel(tableModel);
but, I am able to store the IP Addresses from the table to all.txt file.

but, i can't able to retrieve and display it in the jtable.

whats my problem
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 7 2007
Added on Apr 9 2007
1 comment
122 views