Man!! I'm freaked out, I'm not able to do it
Actually I add dataValues 2d array and colNames array in new created jtable but it doesn't work. Don't know why :S I also wanted to add button before the table but that's doesn't work even...
PLease help me...
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package GUIS;
import Classes.Flight;
import Classes.MyDB;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
/**
*
* @author Umar Ali
*/
public class JTableComponent extends javax.swing.JFrame{
public static void main(String[] args)
{
new JTableComponent();
}
public JTableComponent() {
JFrame frame = new JFrame("Creating JTable Component Example!");
JPanel panel = new JPanel();
MyDB db= new MyDB();
db.connect();
ArrayList<Flight> f = new ArrayList<Flight>();
f = db.GetFlightInfo();
int length = f.size();
String[] colNames = {"FlighNo", "Airline", "Origin", "Destination", "Dept Time", "Arr Time"};
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();
}
}
}
for(int h=0; h<length; h++){
for(int m=0; m<6; m++)
System.out.print(dataValues[h][m] + " ");
System.out.println();
}
//String data[][] = {{"vinod","BCA","A"},{"Raju","MCA","b"},
//{"Ranjan","MBA","c"},{"Rinku","BCA","d"}};
//String col[] = {"Name","Course","Grade"};
JTable table = new JTable(dataValues, colNames);
panel.add(table,BorderLayout.CENTER);
this.setSize(500, 400);
this.setVisible(true);
}
}
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package GUIS; import Classes.Flight; import Classes.MyDB; import javax.swing.*; import java.awt.*; import java.util.ArrayList; /** * * @author Umar Ali */ public class JTableComponent extends javax.swing.JFrame{ public static void main(String[] args) { new JTableComponent(); } public JTableComponent() { JFrame frame = new JFrame("Creating JTable Component Example!"); JPanel panel = new JPanel(); MyDB db= new MyDB(); db.connect(); ArrayList<Flight> f = new ArrayList<Flight>(); f = db.GetFlightInfo(); int length = f.size(); String[] colNames = {"FlighNo", "Airline", "Origin", "Destination", "Dept Time", "Arr Time"}; 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(); } } } for(int h=0; h<length; h++){ for(int m=0; m<6; m++) System.out.print(dataValues[h][m] + " "); System.out.println(); } //String data[][] = {{"vinod","BCA","A"},{"Raju","MCA","b"}, //{"Ranjan","MBA","c"},{"Rinku","BCA","d"}}; //String col[] = {"Name","Course","Grade"}; JTable table = new JTable(dataValues, colNames); panel.add(table,BorderLayout.CENTER); this.setSize(500, 400); this.setVisible(true); } }
Thanks in advance