User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 426,790 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,772 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 18618 | Replies: 3
Reply
Join Date: Nov 2004
Posts: 12
Reputation: bsunkel is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
bsunkel bsunkel is offline Offline
Newbie Poster

Help How to make JTable cell not Editable

  #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!!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2004
Posts: 604
Reputation: freesoft_2000 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: How to make JTable cell not Editable

  #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

   textarea1 = (JTextArea)table1.getEditorComponent();
   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  
Join Date: Jul 2008
Posts: 1
Reputation: obedia200 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
obedia200 obedia200 is offline Offline
Newbie Poster

Re: How to make JTable cell not Editable

  #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  
Join Date: May 2007
Location: USA
Posts: 2,843
Reputation: Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all 
Rep Power: 12
Solved Threads: 283
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: How to make JTable cell not Editable

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 6:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC