| | |
How to make JTable cell not Editable
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
Hi everyone,
It really depends on what your default editor component is
if your component is say a JTextArea the do the following
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
It really depends on what your default editor component is
if your component is say a JTextArea the do the following
Java Syntax (Toggle Plain Text)
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
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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
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...)
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...)
![]() |
Similar Threads
- News Story: It's For You: Choosing the Best Cell Phone Package (Upcoming News Stories)
- Jtable cell renderer (Java)
- Validate jTable cell value. (Java)
- new to Swing, JTable questions (Java)
- JTable Cell Renderers (Java)
Other Threads in the Java Forum
- Previous Thread: Stuck: Exception Handling and reading text from file
- Next Thread: send sms message from pc to mobile
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor






