We help IT Professionals succeed at work.

JTable  cell editing problem

venkat9999
venkat9999 asked
on
Hi ,

I have a problem here that I created JTable by using my own TableModel and in this table only two columns are editable and I have  a method to save changes in that editable cells and I am calling this method in editingStopped() method but this method never called.

I have one more point to tell u that I am calling isCellEditable() and getCellEditor() methods in my table class and if I commented getCellEditor() then it is working properly.
here I am sending my code too.
I would be appreciated if any one could help me in this.

import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.table.*;

import com..businessobjects.*;
import com..businessobjects.lookups.*;
import com..ui.*;
import com..ui.communication.*;
import com..ui.core.*;
import com..ui.util.*;

/**
 * Insert the type's description here.
 * Creation date: (9/17/01 4:54:31 PM)
 * @author: Lois Buwalda
 */
public class DisputeRevenueDialog extends MontageDialog {
    // list of revenue items
    AbstractList revenueList;

    // Table
    private DisputeRevenueTable revenueTable;

    // Scrollable pane for table
    ScrollableTablePane scrollablePane;

    // Buttons
    private MontageButton totalBillButton;
    private MontageButton totalRateButton;
    private MontageButton cancelButton;
    private MontageButton okButton;

    // Table Models
    RevenueTableModel revenueModel = new RevenueTableModel();

   static MontageCurrency newValue;

class RevenueTableModel extends AbstractListTableModel {
    public static final int RATE_COLUMN = 0;
    public static final int DATE_COLUMN = 1;
    public static final int PECO_REVENUE_COLUMN = 2;
    public static final int PECO_DISPUTE_COLUMN = 3;
    public static final int SUPPLIER_REVENUE_COLUMN = 4;
    public static final int SUPPLIER_DISPUTE_COLUMN = 5;
    public static final int SUPPLIER_COLUMN = 6;

    public RevenueTableModel(AbstractList revenueRecords) {
        this();
        setData(revenueRecords);
    }

    public RevenueTableModel() {
        super(new String[] { "Rate", "Date", "PECO Revenue", "PECO Disp. Amt", "Supplier Revenue", "Supplier Disp. Amt", "Supplier" });
    }

    public Object getValueAt(int row, int col) {

        AbstractList data = getData();
        DisputedRevenue record = (DisputedRevenue) data.get(row);
        Object value;

        switch (col) {

            case RATE_COLUMN :
                value = record.getRateCode();
                break;

            case DATE_COLUMN :
                value = record.getDate();
                break;

            case SUPPLIER_COLUMN :
                value = record.getSupplierName();
                break;

            case PECO_REVENUE_COLUMN :
                value = record.getPecoRevenue();
                break;

            case PECO_DISPUTE_COLUMN :
                      value = record.getPecoDisputedAmount();

                      break;

            case SUPPLIER_REVENUE_COLUMN :
                value = record.getSupplierRevenue();
                break;

            case SUPPLIER_DISPUTE_COLUMN :
                value = record.getSupplierDisputedAmount();
                break;

            default :
                value = "";
        }

        return value;
    }
}

class DisputeRevenueTable extends ScrollableTable {
//   pv.jfcx.PVTableEditor doubleEditor = new pv.jfcx.PVTableEditor(new MontageNumericField(), pv.jfcx.JPVTable.DOUBLE);
     pv.jfcx.PVTableEditor doubleEditor = new pv.jfcx.PVTableEditor(new MontageCurrency(), pv.jfcx.JPVTable.CURRENCY);

    public DisputeRevenueTable() {
        super(revenueModel, 25);
    }

    protected DefaultTableColumnModel getDefaultColumnModel() {
        columnModel = new DefaultTableColumnModel();

        TableModel tableModel = this.getModel();

        columnModel.addColumn(newColumn(0, 55, tableModel.getColumnName(0)));
        columnModel.addColumn(newColumn(1, 55, tableModel.getColumnName(1), MontageCellRendererFactory.getDateRenderer()));
        columnModel.addColumn(newColumn(2, 110, tableModel.getColumnName(2), MontageCellRendererFactory.getNumberRenderer()));
        columnModel.addColumn(newColumn(3, 110, tableModel.getColumnName(3), MontageCellRendererFactory.getNumberRenderer()));
        columnModel.addColumn(newColumn(4, 110, tableModel.getColumnName(4), MontageCellRendererFactory.getNumberRenderer()));
        columnModel.addColumn(newColumn(5, 110, tableModel.getColumnName(5), MontageCellRendererFactory.getNumberRenderer()));
        columnModel.addColumn(newColumn(6, 230, tableModel.getColumnName(6)));
           return columnModel;
    }
  //  TableColumn tableColumn = getColumnModel().getColumn(3);
//      tableColumn.setCellEditor(doubleEditor);
   

/*        public boolean isCellEditable(int rowIndex, int columnIndex) {
        if (columnIndex == RevenueTableModel.PECO_DISPUTE_COLUMN || columnIndex == RevenueTableModel.SUPPLIER_DISPUTE_COLUMN)
              {TableColumn tableColumn = getColumnModel().getColumn(columnIndex);
                tableColumn.setCellEditor(doubleEditor);
            return true;}
        else
            return false;
    }
*/
        public boolean isCellEditable(int rowIndex, int columnIndex) {
        if (columnIndex == RevenueTableModel.PECO_DISPUTE_COLUMN || columnIndex == RevenueTableModel.SUPPLIER_DISPUTE_COLUMN)
              return true;
        else
            return false;
    }

    public TableCellEditor getCellEditor(int row, int column) {
        if (column == RevenueTableModel.PECO_DISPUTE_COLUMN || column == RevenueTableModel.SUPPLIER_DISPUTE_COLUMN)
              return doubleEditor;
            return super.getCellEditor();
    }

        
  /*  public void editingCanceled(ChangeEvent e) {
          editCellCanceled(this, e);
        super.editingCanceled(e);
    }
*/
   public void editingStopped(ChangeEvent e) {
            editCellStopped(this, e);
        super.editingStopped(e);
    }

/*      public void editingStopped(ChangeEvent e) {
            pv.jfcx.PVTableEditor editor = new pv.jfcx.PVTableEditor(new MontageCurrency(), pv.jfcx.JPVTable.CURRENCY);
            if (editor != null) {
                  Object value = editor.getCellEditorValue();
                  setValueAt(value, editingRow, editingColumn);
                  removeEditor();
            }
      }
*/
    public TableCellRenderer getCellRender(int row, int column) {
          TableColumn tableColumn = getColumnModel().getColumn(column);
          tableColumn.setCellEditor(doubleEditor);
            TableCellRenderer renderer = tableColumn.getCellRenderer();
            if (renderer == null) {
                  renderer = getDefaultRenderer(getColumnClass(column));
            }
            return renderer;
      }
      }
}
Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
10 questions asked
2 questions graded
And the last question you graded was 18 months ago.

Author

Commented:
waiting for the reply.

Author

Commented:
waiting for the reply.
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
We're waiting for u to accept answers to a few of your previous question :>

Author

Commented:
I accepted all my previous questions and I am waiting for answer for my current question regarding JTable cellediting problem.I would be appreciated if you answer my new question.
Thanks,
Raj.

Author

Commented:
Hi,

I need help in cell editing problem.I post this question long back ,really I don not understand how to assign points ,if really needed I can give more points but I need help as soon as possible.

Thanks,
ven.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.