如何使JTable的单个Cell不可编辑 [英] How to make individual Cell of a JTable Uneditable
本文介绍了如何使JTable的单个Cell不可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我的JTable使用以下单元格模型:
I am using the following cell Model for my JTable:
this.setModel(new DefaultTableModel
(
new Object [][] {
{"Item ID", ""},
{"Radius", 0},
{"Center", 0,0},
{"Mass", 0}
},
new String []
{
"Property", "Value"
}
)
{
Class[] types = new Class []
{
String.class, Object.class
};
boolean[] canEdit = new boolean []
{
false, true
};
@Override
public Class getColumnClass(int columnIndex)
{
return types [columnIndex];
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex)
{
return canEdit [columnIndex];
}
});
但这会将整行和列设置为可编辑/不可编辑。如何将单个单元格(1,1)设置为不可编辑?
but this sets the whole row and column editable/uneditable. How can i set the individual cell say (1,1) as uneditable?
推荐答案
怎么能我将单个单元格说(1,1)设置为不可编辑?
How can i set the individual cell say (1,1) as uneditable?
通过简单地使用传递的行和列索引
By simply using the passed row and column index
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return !( rowIndex == 1 && columnIndex == 1 );
}
这篇关于如何使JTable的单个Cell不可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文