How to make JTable cell not Editable

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 12
Reputation: bsunkel is an unknown quantity at this point 
Solved Threads: 0
bsunkel bsunkel is offline Offline
Newbie Poster

How to make JTable cell not Editable

 
0
  #1
Dec 6th, 2004
Hey there!

I have been trying to get all my JTable cells to be not Editable so you can't change the info displayed on the JTable. It sounds easy to do but I cant seem to do it.

Any help would be appreciated
Thanks!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: How to make JTable cell not Editable

 
0
  #2
Dec 6th, 2004
Hi everyone,
It really depends on what your default editor component is
if your component is say a JTextArea the do the following

  1.  
  2. textarea1 = (JTextArea)table1.getEditorComponent();
  3. textarea1.setEditable(false);

One more thing do not forget to add a table listener so that no matter which cell is clicked it cannot be edited or in your initialization you can do a loop an set all cells to uneditble mode

I you have any other questions on this subject post them here

Richard West
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1
Reputation: obedia200 is an unknown quantity at this point 
Solved Threads: 0
obedia200 obedia200 is offline Offline
Newbie Poster

Re: How to make JTable cell not Editable

 
0
  #3
Jul 1st, 2008
Hi,
I guess you can implement the isEditable() method in your table model and return false and you table will not be editable. Let's see a quick example

public class MyTableModel extends AbstractTableModel{

public void isEditable(){
return false;
}
}

Then you have a table and you set its model to a MyTableModel object eg.

JTable table = new JTable();
table.setModel(new MyTableModel());

Remember to implement MyTableModel well so that it will have some data. I hope this helps
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,492
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 519
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: How to make JTable cell not Editable

 
0
  #4
Jul 1st, 2008
AbstractTableModel.isCellEditable(int,int) returns false by default, so you don't need to override it to get that behavior.

The DefaultTableModel implementation of that method returns true by default, so that one must be overriden if you wish to make cells un-editable.

(And the post you are responding to is over 3 years old...)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC