Hello Guys
I need help with adding new row in a JTable.
I have created the JTable using Netbeans IDE under Swing Controls. Then I removed all the columns, so that I would add them manually.
Now, the function GetFlightInfo() returns an ArrayList with n numbers of rows with 6 columns. I tried each and every way to put the columns and data in JTable (labeled as FlightInformation in my code), but it never worked.
Please help me out, my project is stuck just because of this problem. And I need to use JTable at multiple places, so it's very important for me...
Here's the code
MyDB db= new MyDB();
db.connect();
ArrayList<Flight> f = new ArrayList<Flight>();
f = db.GetFlightInfo();
String[] colNames = {"FlightNo", "Airline", "Origin", "Destination", "Dept Time", "Arr Time"};
int length = f.size();
String dataValues[][] = new String[length][6];
for(int i=0; i<length; i++){
for(int j=0; j<6; j++){
if(j==0){
dataValues[i][j] = ((Flight)f.get(i)).getFlightNo();
}
else if(j==1){
dataValues[i][j] = ((Flight)f.get(i)).getAirline();
}
else if(j==2){
dataValues[i][j] = ((Flight)f.get(i)).getSourceCity();
}
else if(j==3){
dataValues[i][j] = ((Flight)f.get(i)).getDestinationCity();
}
else if(j==4){
dataValues[i][j] = ((Flight)f.get(i)).getDepartureTime();
}
else if(j==5){
dataValues[i][j] = ((Flight)f.get(i)).getArrivalTime();
}
}
((DefaultTableModel)FlightInformation.getModel()).addRow(dataValues[i]);
}
Thanks alot