mathandjul
mathandjul

Reputation: 41

How can i prevent the possibility to select a particular column in JTable?

I want to disable the possibility to select particular columns in a Jtable.

It's easy to disable the selection of certain rows with using the DefaultListSelectionModel class

But I don't know how to do that for columns.

Can any one give me a clue to implement this feature ?

Upvotes: 4

Views: 152

Answers (1)

Jad Chahine
Jad Chahine

Reputation: 7169

You can override the method isCellEditable and implement as you want for example,

try this :

DefaultTableModel tableModel = new DefaultTableModel() {
   @Override
   public boolean isCellEditable(int row, int column) {
       //Only the column nb 2
       return column == 2; 
   }
};
table.setModel(tableModel);

Upvotes: 1

Related Questions