[英]How to bind booleans in JTable with JGoodies
I have seven boolean
values in a column of a JTable
that I want to bind to my bean. 我在JTable
一列中有七个boolean
值,我想绑定到我的bean。
How do I bind them? 我如何绑定它们?
All the JTable
binding examples out there focus on binding the table selection, but I only care about what the values of those booleans
are. 所有JTable
绑定示例都集中在绑定表选择上,但我只关心那些booleans
值的含义。
You need to implement your own data model. 您需要实现自己的数据模型。 I give you simplified example that shows idea of usage. 我给你简化的例子,说明用法的想法。 Take a look at getColumnClass method. 看看getColumnClass方法。
Usage: table.setModel(new DataModel(myData)); 用法:table.setModel(new DataModel(myData));
class DataModel extends AbstractTableModel
{
public DataModel(Object yourData){
//some code here
}
@Override
public int getRowCount() {
return yourData.rows;
}
@Override
public int getColumnCount() {
return yourData.colums;
}
@Override
public Class<?> getColumnClass(int col) {
if (col == myBooleanColumn) {
return Boolean.class;
} else {
return null;
}
}
@Override
public boolean isCellEditable(int row, int col)
{
return col >= 0;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return yourData.get(rowIndex,columnIndex);
}
@Override
public void setValueAt(Object aValue, int row, int col) {
yourData.set(aValue,row,col)
this.fireTableCellUpdated(row, col);
}
}
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.