JTable Problem

Hi guys

I am writing a program in java using JTable.,

The code snippet is look like this

//put the datas into vector

v.addElement(""+JTableArrays[11]);

v.addElement(""+JTableArrays[20]);

v.addElement(""+JTableArrays[13]);

v.addElement(""+JTableArrays[12]);

v.addElement(""+JTableArrays[15]);

v.addElement(""+JTableArrays[14]);

//Retrievei.e. get all the vector ele and convert to string

vecArr = new String[v.size()][6];

Iterator itr = v.iterator();

while(itr.hasNext())

{

System.out.println("Inside lop");

vecArr[m][0] = (String)itr.next();

vecArr[m][1] = (String)itr.next();

vecArr[m][2] = (String)itr.next();

vecArr[m][3] = (String)itr.next();

vecArr[m][4] = (String)itr.next();

vecArr[m][5] = (String)itr.next();

m++;

}

// Create a JTable

String[]ColNames1 = {"SNo", "Commodity","Description", "Sum Insured (Euro)", "Rate", "Fragile"};

JTable table1 = new JTable(vecArr,ColNames1);//pass the arrays in Jtable (Problem is here)

//Problem is

When i run the program it will display the result properly but the problem is -- if i retrive 2 rows from the data base then the JTable should automatically create 12 rows 6 columns why?

Actually i need only 2 rows with 6 column in the Jtable

But it will display 12 rows with 6 column (First two row contains data

and other should be blank?)

How can i solve the problem

Please help me

I think it is a logical problem

Pls solve it

Regards

Marimuthu.n

[1685 byte] By [muthu2007a] at [2007-11-27 8:32:45]
# 1

Don't use the "Bold" tag for you entire posting, its purpose it to highlight certain keywords.

Do use the "Code Formatting Tags",

see http://forum.java.sun.com/help.jspa?sec=formatting,

so the posted code retains its original formatting.

Check out this posting for a simple example.

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=5123381

camickra at 2007-7-12 20:28:40 > top of Java-index,Desktop,Core GUI APIs...
# 2

Hi guys

I am writing a program in java using JTable.,

The code snippet is look like this

//put the datas into vector

v.addElement(""+JTableArrays[11]);

v.addElement(""+JTableArrays[20]);

v.addElement(""+JTableArrays[13]);

v.addElement(""+JTableArrays[12]);

v.addElement(""+JTableArrays[15]);

v.addElement(""+JTableArrays[14]);

//Retrieve i.e. get all the vector ele and convert to string

vecArr = new String[v.size()][6];

Iterator itr = v.iterator();

while(itr.hasNext())

{

System.out.println("Inside lop");

vecArr[m][0] = (String)itr.next();

vecArr[m][1] = (String)itr.next();

vecArr[m][2] = (String)itr.next();

vecArr[m][3] = (String)itr.next();

vecArr[m][4] = (String)itr.next();

vecArr[m][5] = (String)itr.next();

m++;

}

// Create a JTable

String[]ColNames1 = {"SNo", "Commodity","Description", "Sum Insured (Euro)", "Rate", "Fragile"};

JTable table1 = new JTable(vecArr,ColNames1); //pass the arrays in Jtable (Problem is here)

//Problem is

When i run the program it will display the result properly but the problem is -- if i retrive 2 rows from the data base then the JTable should automatically create 12 rows 6 columns why?

Actually i need only 2 rows with 6 column in the Jtable

But it will display 12 rows with 6 column (First two row contains data

and other should be blank?)

How can i solve the problem

Please help me

I think it is a logical problem

Pls solve it

Regards

Marimuthu.n

muthu2007a at 2007-7-12 20:28:41 > top of Java-index,Desktop,Core GUI APIs...
# 3
1) You where asked to use the "Code Formatting Tags"2) You where given a link to a working example
camickra at 2007-7-12 20:28:41 > top of Java-index,Desktop,Core GUI APIs...