JTable & SetCellEditor

I have a JTable with data.how can i set the cellEditor to only first row (but for all the columns in the first row) here is the code i am using..

field=new JTextField();

int cols = table.getModel().getColumnCount();

int row = table.getModel().getRowCount();

int getFirstRow = table.getSelectedRow();

if(getFirstRow==0){

for(int i= 0; i< cols ;i++){

TableColumn col = table.getColumnModel().getColumn(i);

col.setCellEditor(new DefaultCellEditor(field));

}

}

Here ,I want to set a Text filed as the DefaultCellEditor so that I can further add a documentlistener to this Textfield for filtering functionality.The filter part is working though.

But when I use this code every cell in the Table has a cellEditor..but i want only the First row with all the columns to have a cellEditor..

Secondly ,When i enter some text for filtering rows,how can i avoid the data not to be shown on the first row. b'coz i exclusively want this row to be used for having inputs for the filtering rows. Please Help..

[1426 byte] By [sas_21a] at [2007-11-27 6:19:37]
# 1

Just derive a new class from DefaultCellEditor and check which cell is goint to be edited in getTableCellEditorComponent() Method. this method will be called before cell should start editing. Moreover this method parameter contains information about which row and column to be edited. So if row > 0 then dont allow to edit. for others use Super.appropriateMethod() in derived class

PremKumarUa at 2007-7-12 17:34:24 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks for the Reply...But can u post an working example..that will be a great help..
sas_21a at 2007-7-12 17:34:24 > top of Java-index,Desktop,Core GUI APIs...
# 3
Override the getCellEditor(...) method. When editing the first row return your custom editor else return the super.getCellEditor(...).
camickra at 2007-7-12 17:34:24 > top of Java-index,Desktop,Core GUI APIs...
# 4

Hello ,

I tried extending a class to DefaultCellEditor and overriding the methods like getTableCellEditor(..) and getCelleditorValue(..)...but the purpose is not solved..after doing this i am still not able to make the first row with have the setcelleditor ...if anyone can help me with an example ,that will be a great help.

sas_21a at 2007-7-12 17:34:24 > top of Java-index,Desktop,Core GUI APIs...
# 5
> and overriding the methods like getTableCellEditor(..) I suggested overriding the getCellEditor(...) method of JTable. You can search the forums for examples I've posted if you need more help.
camickra at 2007-7-12 17:34:24 > top of Java-index,Desktop,Core GUI APIs...