JTable Java : How to make JTable cells editable or not editable using DefaultTableModel.

Here is a little solution to make the cells of JTable  editable or not editable.

Here I have coded to make the cells of  Column-1 not editable but cells of Column-2 and Column-3 are editable.

Code Example:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

class SimpleTableTest extends JFrame


private JPanel topPanel ;

private JTable table;

private JScrollPane scrollPane;

private String[] columnNames= new String[3];

private String[][] dataValues=new String[3][3] ;

public SimpleTableTest()


setTitle(“JTable Cell Not Editable”);


topPanel= new JPanel();

topPanel.setLayout(new BorderLayout());



columnNames=new String[] {“Column 1” , “Column 2” , “Column 3”};

 dataValues = new String[][]   {





 TableModel model=new myTableModel();

 table =new JTable( );



 scrollPane=new JScrollPane(table);



            public class myTableModel extends DefaultTableModel


                myTableModel( )



                          System.out.println(“Inside myTableModel”);


                        public boolean isCellEditable(int row,int cols)


                           if(cols==0 ){return false;}

      //It will make the cells of Column-1 not Editable

                              return true;                                                                                    



            public static void main(String args[])


            SimpleTableTest mainFrame=new SimpleTableTest();





JTable cell editable or non editable

One Response to JTable Java : How to make JTable cells editable or not editable using DefaultTableModel.

  1. Rehling says:

    Good!!! Bookmarked this page that has this amazing content. Will come back to see if there are any updates. You, the author, are a master. Thanks


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s