Making JTable cells uneditable

后端 未结 4 579
独厮守ぢ
独厮守ぢ 2020-12-19 23:25

I am trying to make all the cells of a JTable uneditable when double clicked by the user. I have read a lot of forum posts and the general consensus is to create a new table

4条回答
  •  猫巷女王i
    2020-12-19 23:59

    Just override the isCellEditable method of the DefaultTableModel class. The quick way to do this:

    JTable table = new JTable();
    DefaultTableModel dtm = new DefaultTableModel(0, 0) {
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    table.setModel(dtm);
    

提交回复
热议问题