File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making all Cells NotEditable in a JTable

 
Parth Bhatt
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am working on a Swing App which deals with a JTable. I Have written the following code and it works fine for me, The only problem is that all rows in the table are editable by default. I want to change them to "Not Editable".

Apart from this, the code works absolutely fine for me. So, unless unavoidable, i do not wish to write a custom class inheriting AbstractTableModel.

Can someone suggest a way thru which i could make each cell in the table Not Editable, preferably without writing my own TableModel class ? i.e. is there a method in JTable or DefaultTableModel which will allow me to make each cell not editable...?


Here's my code...

 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Justin Fox
Ranch Hand
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you dont want the JTable editable at all just set the actual
JTable object.setEditable(false);


wouldn't that have the same effect?


Justin
 
Tapan Maru
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which constructor of JTable are you using? I am generally write My own tablemodel class which extends AbstractTableModel class of javax.swing.table package. In that class there is one method you can override:

public boolean isCellEditable(int row, int col) {
return false;
}

you can override the above method which above implementation so that all cells will be un-editable.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic