How To Use Inbuilt Cell Editor of JTable

When I called function getCellEditor() function of JTable then NullPointerException is occured.

I am not to use my own CellEditor. where as I wana use inbuilt JTable CellEditor

PART of my Source Code:

DefaultCellEditor dce=(DefaultCellEditor) ((DefaultTableColumnModel)grid.getColumnModel()).getColumn(c).getCellEditor();

dce.getComponent().addFocusListener(new TextFocus(true));

first line gives NullPointerException

Please Help Me

If you help me, I will be very thankful to u...

[529 byte] By [gajesha] at [2007-11-27 10:29:13]
# 1

SORRY! Error is in 2nd Line:-

My source fragment is:

class FrmTestReport {

private final byte RESULT=7;

private JTable grid;

public FrmTestReport() {

private final byte RESULT=7;//Breaker

grid = new javax.swing.JTable()

{

public JToolTip createToolTip()

{

return new JMultiLineToolTip();

}

};

grid.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

{null, null, null, null, null, null, null, null, null}

},

new String [] {

"S.No.", "TestID", "Test Name", "Low", "High", "Chg", "GroupID", "Result", "Remarks"

}

){

Class[] types = new Class [] {

java.lang.Short.class, java.lang.Long.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Long.class, java.lang.Integer.class, java.lang.String.class

};

boolean[] canEdit = new boolean [] {

false, false, false, false, false, false, false, true, true

};

public Class getColumnClass(int columnIndex) {

return types [columnIndex];

}

public boolean isCellEditable(int rowIndex, int columnIndex) {

return canEdit [columnIndex];

}

});

grid.setToolTipText("IF YOU ARE WORKING WITH TABLE:\n\n 1.<F2> \tTo edit cell\n 2.<Enter>\tTo move next row in same column \n 3.<Arrows>\tTo move arround cells in Table\n 4.<Tab>\tTo jump with cell\n 5.<Ctrl+Tab>\tTo transfer focus");

grid.setCellSelectionEnabled(true);

jScrollPane2.setViewportView(grid);

DefaultCellEditor dce=(DefaultCellEditor) ((DefaultTableColumnModel)grid.getColumnModel()).getColumn(RESULT).getCellEditor();

dce.getComponent().addFocusListener(new TextFocus(true));

}

}

gajesha at 2007-7-28 17:56:13 > top of Java-index,Desktop,Core GUI APIs...