Making JTable uneditable
3 posts in topic
Flat View  Flat View

Posted By:   Weiliang_Zhuang
Posted On:   Sunday, September 15, 2002 01:31 AM

is it possible to make a JTable uneditable but at the same time, users are able to make selections on the table?

Re: Making JTable uneditable

Posted By:   teppo_kauppinen  
Posted On:   Sunday, September 29, 2002 03:05 PM

add the following code before initializing JTable (add the size you want your table to be to int row & int col)

DefaultTableModel deftm = new DefaultTableModel(int row, int col){

public boolean isCellEditable(int row, int column) {

return false;



JTableBoard = new JTable(deftm);

Re: Making JTable uneditable

Posted By:   eitan_worcel  
Posted On:   Wednesday, September 18, 2002 05:30 AM

The simplest way is to use the setEnabled() method with the boolean false value. It prevents user from editing the table but still responds to mouse events, which you can catch the same way you're used to.

hope it helped

Worcel Eitan

Re: Making JTable uneditable

Posted By:   Prashanth_Sukumaran  
Posted On:   Sunday, September 15, 2002 04:51 AM

Hi Weiliang,

For the isCellEditable return false.

The user will be able to select the rows and columns but will not be editable.

isCellEditable(int rowIndex, int columnIndex)

Returns false if the cell at rowIndex and columnIndex is not editable

If you are using the DefaultTableModel then it returns true regardless of the row and the column index. So you got to override this method and return false or you can also implement the AbstractTableModel, where you can return a false isrespective of the row the column index.


Prashanth Sukumaran.
About | Sitemap | Contact