简体   繁体   中英

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM