U
Urraco
"The trouble is, the JTable is only displaying the first element in
rowData."
I'm having trouble displaying all the information in a JTable. First I
create two vectors:
rowData = new Vector<Vector<String>>( ); //info obtained
from DataBase
colNames = new Vector<String>( );
I fill colNames with column name. Then I fill rowData depending on the
selection from a JComboBox using this method:
private void populateRowData( ) {
rowData.clear();
System.out.println("After Clear " + rowData); //for
debug
try {
rs.beforeFirst( ); // rs RecordSet
int position = account.getSelectedIndex(); //
account - JComboBox
while(rs.next( )) {
if (
rs.getString(3).equals(accountName.elementAt(position).elementAt(0)) &&
rs.getString(2).equals(accountName.elementAt(position).elementAt(1)) )
{
Vector<String> temp = new
Vector<String>( );
temp.add(rs.getString(1));
//date
temp.add(rs.getString(5));
//trans type
temp.add(rs.getString(6));
//trans amount
temp.add(rs.getString(7));
//running bal
rowData.add(temp);
}
}
System.out.println("After While " + rowData); //
for debug
}
catch(SQLException sqle) {
System.err.println(sqle);
}
}
finally I create a JTable:
table = new JTable(rowData, colNames);
sp = new JScrollPane(table);
The trouble is, the JTable is only displaying the first element in
rowData. If I print rowData to the black window I can see several
elements. The JTable does change with a different selection on the
JComboBox but for some reason only the first element in rowData is
displayed even if there are several elements in the Vector.
I've thought about using some kind of TableModel and changing the code
to this:
TableModel model = new AbstractTableModel( );
table = new JTable(model);
sp = new JScrollPane(table);
But how do I feed the two Vectors to the model and how do I update it
later? I'm just not sure this will help me as I don't really know
where my problem lies.
Any help or advice would be appreciated.
Urraco
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
rowData."
I'm having trouble displaying all the information in a JTable. First I
create two vectors:
rowData = new Vector<Vector<String>>( ); //info obtained
from DataBase
colNames = new Vector<String>( );
I fill colNames with column name. Then I fill rowData depending on the
selection from a JComboBox using this method:
private void populateRowData( ) {
rowData.clear();
System.out.println("After Clear " + rowData); //for
debug
try {
rs.beforeFirst( ); // rs RecordSet
int position = account.getSelectedIndex(); //
account - JComboBox
while(rs.next( )) {
if (
rs.getString(3).equals(accountName.elementAt(position).elementAt(0)) &&
rs.getString(2).equals(accountName.elementAt(position).elementAt(1)) )
{
Vector<String> temp = new
Vector<String>( );
temp.add(rs.getString(1));
//date
temp.add(rs.getString(5));
//trans type
temp.add(rs.getString(6));
//trans amount
temp.add(rs.getString(7));
//running bal
rowData.add(temp);
}
}
System.out.println("After While " + rowData); //
for debug
}
catch(SQLException sqle) {
System.err.println(sqle);
}
}
finally I create a JTable:
table = new JTable(rowData, colNames);
sp = new JScrollPane(table);
The trouble is, the JTable is only displaying the first element in
rowData. If I print rowData to the black window I can see several
elements. The JTable does change with a different selection on the
JComboBox but for some reason only the first element in rowData is
displayed even if there are several elements in the Vector.
I've thought about using some kind of TableModel and changing the code
to this:
TableModel model = new AbstractTableModel( );
table = new JTable(model);
sp = new JScrollPane(table);
But how do I feed the two Vectors to the model and how do I update it
later? I'm just not sure this will help me as I don't really know
where my problem lies.
Any help or advice would be appreciated.
Urraco
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)