Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-05-2009, 09:52 PM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default JTable, Vector, File, Problem.
<SOLVED>


Evening all. Have a small problem. Still trying to understand JTable. Problem is that I have 1 file named row.txt. The code below is for reading that file and put it in vector row. when i do System.out.print(row) it prints out all of it. But in my table it only showing first row in the file. ex if file contain.

row1 row2 row3
row4 row5 row6

Table only showing row1 row2 row2. if i add more cols. they appear. what have i missed?

Code:
public class RowClass extends DefaultTableModel {
     File file = new File("c://java/row.txt");
     FileInputStream fis = null;
     BufferedInputStream bis = null;
     DataInputStream dis = null;
     int count;
     String str;
     String[] arr;
         
void rowVoid() {
      
   try{
      fis = new FileInputStream(file);
      bis = new BufferedInputStream(fis);
      dis = new DataInputStream(bis);
      while ((str = dis.readLine()) !=null ){
      arr = str.split(" ");
      count++;
      for (int i = 0; i < arr.length; i++){
       row.addElement(arr [i]);
       System.out.println(arr [i]);
        }
      }
      for (int i = 0; i < count; i++) {
      rowData.addElement(row);
        }
      fis.close();
      bis.close();
      dis.close();
      }catch  (IOException e) {
      e.getStackTrace();    
      System.out.println("Error" +e.toString() );
       }
    }
 }

Last edited by ocean; 11-06-2009 at 08:56 AM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-06-2009, 04:43 AM
Senior Member
 
Join Date: Jul 2009
Posts: 300
Rep Power: 1
camickr is on a distinguished road
Default
You need to create a new "row" for every line of data in the file.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-06-2009, 07:56 AM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default
That´s what i thougth i did. with the rowData loop. Would be happy if someone could point out what i do wrong.

Code:
    Vector<Vector> rowData = new Vector<Vector>();
    Vector<String> col = new Vector<String>();
    Vector<String> row = new Vector<String>();

And the loops do

Code:
while ((str = dis.readLine()) !=null ){

      arr = str.split(" ");
      count++; 

      for (int i = 0; i < arr.length; i++){
       row.addElement(arr [i]);
         }
      

     for (int i = 0; i < count; i++) {
      rowData.add(row);
      }

I dreamt a nigthmare about a vector that chased me tonight. Think i have overworked my small brain and need a break.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-06-2009, 08:39 AM
Senior Member
 
Join Date: Jul 2009
Posts: 300
Rep Power: 1
camickr is on a distinguished road
Default
How many times does

Code:
row = new Vector<String>()
appear in your code?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-06-2009, 08:51 AM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default
Oo it were that easy. Big thanks to you camickr.

Code:
while ((str = dis.readLine()) !=null ){
      arr = str.split(" ");
      row = new Vector<String>();
      for (int i = 0; i < arr.length; i++){   
          row.addElement(arr [i]);
      } 
     rowData.add(row);
      }

And now it works as i like. This forum is amasing. Thank´s for having patient with me.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with vector morghul New To Java 3 11-04-2009 03:24 AM
Jtable duplicates through Hashtable (JTable condition problem) my assignment plz help salmanpirzada1 Advanced Java 2 05-15-2008 11:15 AM
How to Save/Load Vector to/from file Java Tip java.lang 0 04-14-2008 09:37 PM
Vector problem Ace_Of_John New To Java 1 01-27-2008 09:53 PM
vector problem mambo_jumbo New To Java 1 11-17-2007 11:44 PM


All times are GMT +2. The time now is 11:09 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org