Disable userinput on a JTable
Is there a wa开发者_运维知识库y to disable editing a JTable after creating it. Because my JTable is created automaticly using GUI Tools and I cannot edit the source code where it creates the JTable.
Cheers
Yes, but it's in your TableModel. There's a method called isCellEditable If you can't manipulate your model, can try something like this:
jtableObject.setModel(jtableObject().getModel(){
isCellEditable(int rowIndex, int columnIndex) {
return false;
}
});
Your object must be created! It's a little confusing code. There you're creating an anonymous class.
Remember, when you talk about "editing", what you're actually editing, is the data stored in that table. The data is represented in the TableModel.
If you have access to the source code, and have a reference to the frame, you could still programatically traverse the container tree until you get to the table, then call whatever you need on it.
精彩评论