抽象表模型isCellEditable()重写不会使单元格可编辑

时间:2014-09-15 09:43:54

标签: java jtable abstracttablemodel

我正在使用TableModel实现JTable。 我有一个问题是让细胞可以在这个特定的细胞上编辑。 这是我的isCellEditable覆盖TableModel

 @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
        }

使用此TableModel的Jtable实例并不能使单元格可编辑。

首先,我将JScrollPane与The JTable一起实现:

caseTM = new CaseTableModel(factory,caseList);
            caseListTable = new JTable(caseTM);
            caseScrollPanel = new JScrollPane(caseListTable);

以下是CaseTableModel的代码:

public class CaseTableModel extends AbstractTableModel {

    Factory f;
    ArrayList<Case> cList;

    public CaseTableModel(Factory f,ArrayList<Case> caseList) {
        this.f=f;
        cList=caseList;
    }


    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return cList.get(0).getClass();
    }

    @Override
    public int getColumnCount() {
        return 14;
    }

    @Override
    public String getColumnName(int columnIndex) {
        switch (columnIndex) {
        case 0:
            return "Numéro d'Affaire";
        case 1:
            return "Client";
        case 2:
            return "Projet";
        case 3:
            return "Position";
        case 4:
            return "Status";
        case 5:
            return "Date Début";
        case 6:
            return "Date Fin";
        case 7:
            return "Nombre de jours facturés";
        case 8:
            return "Daily Rate";
        case 9:
            return "IGD";
        case 10:
            return "Autres Conditions";
        case 11:
            return "Echeance de paiement";
        case 12:
            return "Date de paiment";
        case 13:
            return "Montant HT";
        case 14:
            return "Montant TTC";
        default:
            return "FAUX!";
        }
    }

    @Override
    public int getRowCount() {
        return cList.size();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
        case 0:
            return cList.get(rowIndex).getNumber();
        case 1:
            return cList.get(rowIndex).getClient();
        case 2:
            return cList.get(rowIndex).getProject();
        case 3:
            return cList.get(rowIndex).getPositon();
        case 4:
            return cList.get(rowIndex).getStatus();
        case 5:
            return cList.get(rowIndex).getStartDate();
        case 6:
            return cList.get(rowIndex).getEndDate();
        case 7:
            return cList.get(rowIndex).getNumberOfDayInvoice();
        case 8:
            return cList.get(rowIndex).getDailyRate();
        case 9:
            return cList.get(rowIndex).getDailyIndemnity();
        case 10:
            return cList.get(rowIndex).getOtherConditions();
        case 11:
            return cList.get(rowIndex).getPaymentDueDate();
        case 12:
            return cList.get(rowIndex).getPaymentDate();
        case 13:
            return cList.get(rowIndex).getAmountTaxFree();
        case 14:
            return cList.get(rowIndex).getAmountWithTax();
        default:
            return "FAUX!";
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return true;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        switch (columnIndex) {
        case 0:
            cList.get(rowIndex).setNumber((String) aValue);
            break;
        case 1:
            cList.get(rowIndex).setClient((String) aValue);
            break;
        case 2:
            cList.get(rowIndex).setProject((String) aValue);
            break;
        case 3:
            cList.get(rowIndex).setPositon((String) aValue);
            break;
        case 4:
            cList.get(rowIndex).setStatus((String) aValue);
            break;
        case 5:
            cList.get(rowIndex).setStartDate((Integer) aValue);
            break;
        case 6:
            cList.get(rowIndex).setEndDate((Integer) aValue);
            break;
        case 7:
            cList.get(rowIndex).setNumberOfDayInvoice((Integer) aValue);
            break;
        case 8:
            cList.get(rowIndex).setDailyRate((Double) aValue);
            break;
        case 9:
            cList.get(rowIndex).setDailyIndemnity((Double) aValue);
            break;
        case 10:
            cList.get(rowIndex).setOtherConditions((String) aValue);
            break;
        case 11:
            cList.get(rowIndex).setPaymentDueDate((Integer) aValue);
            break;
        case 12:
            cList.get(rowIndex).setPaymentDate((Integer) aValue);
            break;
        case 13:
            cList.get(rowIndex).setAmountTaxFree((Double) aValue);
            break;
        case 14:
            cList.get(rowIndex).setAmountWithTax((Double) aValue);
            break;
        default:
            break;
        }
        f.updateCase(cList.get(rowIndex));
    }


    public void fireTableDataChangedForThisEmployee(Employee e){
        cList = f.getCasesForThisEmployee(e);
        super.fireTableDataChanged();
    }


}

0 个答案:

没有答案