My Jtable is blank

Posted by mazin on Stack Overflow See other posts from Stack Overflow or by mazin
Published on 2011-01-03T20:00:34Z Indexed on 2011/01/03 20:53 UTC
Read the original article Hit count: 226

Filed under:
|
|
|
|

Hello my q is about a jtable that i have ,i fill it with components from a .txt ,I have a main (menu ) JFrame and by pressing a jbutton i want the jtable to pop out ! My problem is that my jtable is blank and it supposed to show some date !I would appreciated any help , Thanks. this is my ''reading'' class`

public static void main(String[] args) {
     company Company=new company();
    payFrame jframe=new payFrame(Company);
    jframe.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
    jframe.setSize(600,300);
    jframe.setVisible(true);
     readClass();
}
    //diavasma
  public static void readClass(){
    ArrayList<Employee> emp =new ArrayList<Employee>() ;
    //Employee[] emp=new Employee[7];
    //read from file
 try {

   int i=0;
   // int rowCounter;
   // int payments=0;

String inputDocument = ("src/Employees.txt");


FileInputStream is = new FileInputStream(inputDocument);
Reader iD = new InputStreamReader(is);


BufferedReader buf = new BufferedReader(iD);
String inputLine;
while ((inputLine = buf.readLine()) != null) {
            String[] lineParts = inputLine.split(",");

            String email = (lineParts[7]);
            int EmpNo = Integer.parseInt(lineParts[0]);
            String type = lineParts[10];
            int PostalCode = Integer.parseInt(lineParts[5]);
            int phone = Integer.parseInt(lineParts[6]);
            int DeptNo = (short) Integer.parseInt(lineParts[8]);
            double Salary;
            int card = (short) Integer.parseInt(lineParts[10]);
            int emptype = 0;
             int hours=Integer.parseInt(lineParts[11]);
            if (type.equals("FULL TIME")) {
                emptype = 1;
            } else if (type.equals("SELLER")) {
                emptype = 2;
            } else {
                emptype = 3;
            }

            /**
             *  Creates employee instances depending on their type of employment
             *  (fulltime=1, salesman=2, parttime=3)
             */
            switch (emptype) {
                case 1:


                    Salary = Double.parseDouble(lineParts[10]);
                    emp.add(new FullTime(lineParts[1], lineParts[2], EmpNo, 
                            lineParts[3],
                            lineParts[4], PostalCode, phone,
                            email, DeptNo, card, Salary,hours, type));

                    i++;
                    break;

and this is my class where i make my Jtable and fill him

public class company extends JFrame {
    private ArrayList<Employee> emp = new ArrayList<Employee>();
    public void addEmployee(Employee emplo) {

    emp.add(emplo);
}

public ArrayList<Employee> getArray() {
    return emp;
}

public  void getOption1() {

     ArrayList<Employee> employee = getArray();
    JTable table = new JTable();
    DefaultTableModel model = new DefaultTableModel();
    table.setModel(model);
    model.setColumnIdentifiers(new String[]{"Code", "First Name", "Last Name", "Address", "City", "Postal Code", "Phone", "Email",
                "Dept Code", "Salary", "Time Card", "Hours"});
    for (Employee current : employee) {
        model.addRow(new Object[]{current.getempCode(), current.getfirst(), current.getlast(),
                    current.getaddress(), current.getcity(), current.getpostalCode(),
                    current.gettelephone(), current.getemail(), current.getdep(),
                    current.getsalary(), current.getcardcode(), current.getHours()
                });

    }


    table.setPreferredScrollableViewportSize(new Dimension(500, 50));
    table.setFillsViewportHeight(true);
    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane);
   setVisible(true);

    table.revalidate();

© Stack Overflow or respective owner

Related posts about swing

Related posts about jtable