Home:ALL Converter>getColumnName not working correctly

getColumnName not working correctly

Ask Time:2014-07-03T02:31:28         Author:abdelbasset

Json Formatter

I am using a new class for a TableModel that extends AbstractTableModel, but when i try to add the header row it doesn't show. This is the code:

 public class StudentTableModel extends AbstractTableModel {

    private ArrayList<Student> student;
    private ArrayList<Group> groups;
    private int tableType=2;
    public String []coluNamess = {
                                    "id","name",
                                    "last name",
                                    " birth date",
                                    "phone","adress",
                                    "class"
                                 };
    public String  []coluNamesg = {
                                    "id","title",
                                    "level","num"
                                  };

    public String getColumnName(int column ) {
        if(tableType==1) {
            return this.coluNamess[column];
        } else {
            return this.coluNamesg[column];
        } 
    }

    public int getColumnCount() {
        if(tableType==1) {
            return 7;
        } else {
            return 4;
        }
    }

    public int getRowCount() {
        if(tableType==1) { 
            return student.size();
        } else {
            return groups.size();
        }
    }

    public String getValueAt(int row, int colu) {
        if(tableType==1) {
            Student studentm=student.get(row);
            switch(colu) {
                case 0:
                    return  Double.toString((double)studentm.getId());
                case 1:
                    return studentm.getFname();
                case 2:
                    return studentm.getLname();
                case 3:
                    return studentm.getB_date();
                case 4:
                    return studentm.getPhone();
                case 5:
                    return studentm.getAdress();
                case 6:
                    return Double.toString((double)studentm.getGroupId());
            }
        } else if(tableType==2) {
            Group group=groups.get(row);
            switch(colu) {
                case 0:
                    return  Double.toString((double)group.getId());
                case 1:
                    return  group.getTitle();
                case 2:
                    return  group.getLevel();
                case 3:
                    return  Double.toString((double)group.getTime());
            }
        }  
        return null;
    }

    public void setStudent(ArrayList<Student> students) {
        this.student= students;
    }

    public void setGroup(ArrayList<Group> groups) {
        this.groups= groups;
    }

    public void setType(int type) {
        this.tableType=type;
    }
}

The header is not appearing but the content is shown. I don't know where the problem is!!!!

Author:abdelbasset,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/24538508/getcolumnname-not-working-correctly
tenorsax :

Add a table to a scroll pane, ie: new JScrollPane(table). See Adding a Table to a Container for more details:\n\n\n The scroll pane automatically places the table header at the top of\n the viewport. The column names remain visible at the top of the\n viewing area when the table data is scrolled.\n \n If you are using a table without a scroll pane, then you must get the\n table header component and place it yourself.\n",
2014-07-02T18:45:51
yy