Skip to Main Content

Java Programming

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!

Inserting row and row data dynamically with vector in JTable

807603Dec 1 2007 — edited Jan 24 2008
I m newbie. I want to make a program which-
1. Fetch huge (row)data from DB into vector.
2.Then insert this row data in a JTable

Now my questions are-

1. Is it suitable to fetch HUGE(e.g.10,000) data from DB into a Vector. I mean using Vector.

2. How to insert these row data into an existing Jtable . I want to use the same JTable for inserting data each time so that the other properties of the Jtable remains the same.

3.Problem is once I create JTable with a specified row number ,HOW can I later change only the row number of the SAME Jtable as needed.
4. In short, each time there will be as much row as it is in the Vector.I have two columns in my DB table, so I think I can easily get the no. of row by - vector.size()/2 .
Now the code I tried with is as follows-
public class frmUserForm extends JFrame {
//unnecessary code is omitted
String columnNames[] = { "Reference", "Status"};
String row[][];
JTable table;

frmUserForm (){
//making an initial table to be displayed
row=new String[1][2];
    table = new JTable( row,columnNames);
    table.setRowSelectionAllowed( true );
    table.setColumnSelectionAllowed( false );
	//table.setAutoCreateColumnsFromModel( false );
	table.getTableHeader().setForeground(Color.blue);
	table.setRowHeight(20);
	table.setSelectionForeground(Color.red);
	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

  }
public void displayAllRef()
	{
		//getrefData() is a method to get the huge row data from table into   //vector
		Vector refData=user.getrefData();
		System.out.println("REF DATA-"+refData);
		
		int rowno=refData.size()/2;
		row=new String[rowno][2];
		
		table = new JTable( row,columnNames);
		
		Iterator i=refData.iterator();
		
		int count=0;
		while(i.hasNext())
		{
			table.setValueAt((String)i.next(),count,0);
			table.setValueAt((String)i.next(),count,1);
			count++;
		}
		
		scrollpane.getViewport().add(table);
	}

}
As u can see that each time a new Jtable is created to hold the row data. That's why the previous property is not found. How can I insert row data in the same JTable without losing the initial property. And I also want to have the same number of rows as in the vector in the same Jtable each time a new vector is found
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 21 2008
Added on Dec 1 2007
5 comments
1,752 views