Java – how to prevent the possibility of selecting specific columns in JTable?
•
Java
I want to disable the possibility of selecting specific columns in JTable
Using the defaultlistselectionmodel class, you can easily disable the selection of certain rows
But I don't know how to do this for the column
Can anyone give me a clue to realize this function?
Solution
You can override the method iscelleditable and implement it as you wish, 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 content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码