Home arrow static arrow Java Programming [Archive] - How to make DefaultTableModel cells un-editable?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - How to make DefaultTableModel cells un-editable?
This topic has 2 replies on 1 page.

Posts:56
Registered: 3/17/04
How to make DefaultTableModel cells un-editable?  
Jul 23, 2004 7:25 AM



 
I have JTable using DefaultTableModel. The DefaultTableModel is implementing isCellEditable() method and returns false everytime. All cells have become editable, but I want them to be un-editable. How do I do it? Here is the code:

private Object queriedDataRow[]=new String[2];
private MyDefaultTableModel dtm=new MyDefaultTableModel();

private void activateDatabase()
{
try
{
/* code skipped here */
ResultSet rs=st.executeQuery("SELECT * FROM dummy");
while( rs.next() )
{
queriedDataRow[0]=(Object)rs.getString("col1");
queriedDataRow[1]=(Object)rs.getString("col2");
dtm.addRow(queriedDataRow);
}
/* code skipped here */
}

private void drawWindow()
{
JTable table=new JTable(dtm);

/* code skipped here */
}

public class MyDefaultTableModel extends DefaultTableModel
{
String colNames[]={"col1","col2"};
public int getColumnCount()
{
return colNames.length;
}
public String getColumnName(int col)
{
return colNames[col];
}
public boolean isCellEditable(int col)
{
return false;
}
public Class getColumnClass(int col)
{
return getValueAt(0,col).getClass();
}
}
 

Posts:56
Registered: 3/17/04
Re: How to make DefaultTableModel cells un-editable?  
Jul 23, 2004 7:27 AM (reply 1 of 2)



 
got my mistake. The prototype for isCellEditable is wrong :)
 

Posts:10,972
Registered: 10/23/03
Re: How to make DefaultTableModel cells un-editable?  
Jul 23, 2004 7:29 AM (reply 2 of 2)



 
Stare at this signature: [url=http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/table/TableModel.html#isCellEditable(int,%20int)]isCellEditable[/url]
 
This topic has 2 replies on 1 page.