0

Possible Duplicate:
How to make a JTable non-editable

I am developing an application using Netbeans.

I have generated a Report in a JTable format.

It works properly but the rows and colums are editable, and I would them to be non-editable.

Community
  • 1
  • 1
Jayashri
  • 366
  • 4
  • 13
  • 25
  • By NetBeans, you mean the IDE or the platform? Either way, we don't really care for what you want to do I think. Also, do not prefix questions with "java:", tags are herer for this purpose. I took it upon me to rewrite bits of your question. Thank you. – haylem Jul 12 '12 at 03:42
  • Ah, and -1 because of lots of duplicates (see "related" section on the right) and answer is one google search away (and requested to be closed for both of these reasons). – haylem Jul 12 '12 at 03:43

2 Answers2

4

In your table model you can override the isCellEditable() method:

public class MyModel extends DefaultTableModel 
{
   public MyModel(Object[][] data, Object[] cols) 
   {
      super(data, cols);
   }

   public boolean isCellEditable(int row, int col) 
   {
      return false;
   }
}
Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170
1

You are using the NetBeans GUI editor to create your table. In the table's Properties > model, select the desired origin for the model. For example, you can add @Hunter's Mymodel to your source and choose Custom code:

new MyModel(data, cols)

Custom Model

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • @Jayashri: Note how the no-argument constructor fails. Also consider reducing your dependence on the GUI editor, as suggested [here](http://stackoverflow.com/a/2561540/230513). – trashgod Jul 12 '12 at 17:11