本文介绍了在JTable中禁用用户编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
创建JTable组件时,默认情况下启用单元格编辑.如何防止用户编辑JTable的内容?
When a JTable component is created, cell editing is enabled by default. How can I prevent the user from editing the content of a JTable?
推荐答案
JTable使用AbstractTableModel对象.这就是您传递给JTable的构造函数的东西.您可以如下编写自己的AbstractTableModel
A JTable uses an AbstractTableModel object. This is the thing you pass into the constructor of the JTable. You can write your own AbstractTableModel as follows
public class MyTableModel extends AbstractTableModel {
public boolean isCellEditable(int row, int column){
return false;
}
}
然后将您的JTable初始化为
and then initialize your JTable as
JTable myTable = new JTable(new MyTableModel());
这篇关于在JTable中禁用用户编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!