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

Recommended Answers

All 8 Replies

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();

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

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

Well, it was helpful for me now in 2011 :)

Well I made my JTable non-editable by disabling it, i.e., using setEnabled(false). It works in my situation.

and, if you answered this seven years ago, it might even have mattered to the original poster.

i dont think u understand the concept of a forum like this one. it doesnt matter how old the post is. if the matter is still relevant it is most appreciated to post a solution.

me helped this a lot so thanks for the solution.

Smolof, thumbs up to you ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.