i'm trying to populate a JList, and i saw that this is how it supose to work
JTable tabel = new JTable();
tabel = new JTable(row, cols);
while (it.hasNext() && it1.hasNext() && it2.hasNext()
&& it3.hasNext() && it4.hasNext()) {
Object ob[][] = {
{ it.next(), it1.next(), it2.next(), it3.next(), it4.next() }}
DefaultTableModel model = new DefaultTableModel(ob, col);
tabel = new JTable(model);
}
i have 5 fields which are populated from 5 ArrayLists, the data comes from a MySql Database, in my database i have 5 contact
the problem is that it populates my table only with the first contact. If i move the lines:
DefaultTableModel model = new DefaultTableModel(ob, col);
tabel = new JTable(model);
outside the while, of course, it doesn't recognize ob[][],
if i try just to declare
Object ob[][] = null
outside the while() i get an error.
the only solution i found so far is to write
{ it.next(), it1.next(), it2.next(), it3.next(), it4.next() }
for each element i have in database, which is bad programming, so the final code is
while (it.hasNext() && it1.hasNext() && it2.hasNext()
&& it3.hasNext() && it4.hasNext()) {
Object ob[][] = {
{ it.next(), it1.next(), it2.next(), it3.next(),
it4.next() },
{ it.next(), it1.next(), it2.next(), it3.next(),
it4.next() },
{ it.next(), it1.next(), it2.next(), it3.next(),
it4.next() },
{ it.next(), it1.next(), it2.next(), it3.next(),
it4.next() },
{ it.next(), it1.next(), it2.next(), it3.next(),
it4.next() } };
DefaultTableModel model = new DefaultTableModel(ob, col);
tabel = new JTable(model);
}
does anyone have a suggestion?