高手们
我在用AbstractTableModel,我有一个类是继承AbstractTableModel的,其中有一列是boolean类型的,按理来说应该显示checkbox,但是如果这列在第一列的时候就没问题,如果在点击查询之前,我先把这个列拖到其他位置,查询出来就变成false和true了,checkbox再也无法正常显示出来,大家帮帮忙啊,谢谢了。 import javax.swing.table.AbstractTableModel; public class SvcProviderTableModel
extends AbstractTableModel { public Vector colum;
public Vector vrow;
public SvcProviderTableModel() {
colum = new Vector();
vrow = new Vector();
colum.addElement(" "); //0
colum.addElement("title1"); //1
colum.addElement("title2"); //2
colum.addElement("title3"); //3
colum.addElement("title4"); //4
colum.addElement("title5"); //5
colum.addElement("title6"); //6
colum.addElement("title7"); //7
colum.addElement("title8"); //8
colum.addElement("title9"); //9
colum.addElement("title10"); //10
colum.addElement("title11"); //11
colum.addElement("title12"); //12
colum.addElement("title13"); //13
colum.addElement("title14"); //14
colum.addElement("title15"); //15
colum.addElement("title16"); //16
} // new methods public Vector getrowvalues() {
// get all row values return vrow;
} // public int getColumnCount() {
return colum.size();
} public int getRowCount() {
return vrow.size();
} public String getColumnName(int col) {
return colum.elementAt(col).toString();
} public Object getValueAt(int row, int col) {
try {
Vector rowData = (Vector) vrow.elementAt(row);
if (rowData != null) {
return rowData.elementAt(col);
}
return null;
}
catch (Exception e) {
return null;
}
} public void setValueAt(Object value, int row, int col) {
// get the array for the proper row
Vector v = (Vector) vrow.elementAt(row);
// replace the boolean object that changed
v.set(col, value);
} public boolean isCellEditable(int row, int col) {
if (col == 0)
return true;
else
return false;
} public Class getColumnClass(int col) {
if (col == 0)
return Boolean.class;
else
return getValueAt(0, col).getClass();
} public void addRow(Vector someVector) {
vrow.addElement(someVector);
fireTableDataChanged();
} public void removeRow() {
int count = this.getRowCount();
for (int i = 0; i < count; i++) {
vrow.removeElementAt(0);
fireTableDataChanged();
}
} public void removeRow(int row) {
vrow.removeElementAt(row);
fireTableDataChanged();
}
我在用AbstractTableModel,我有一个类是继承AbstractTableModel的,其中有一列是boolean类型的,按理来说应该显示checkbox,但是如果这列在第一列的时候就没问题,如果在点击查询之前,我先把这个列拖到其他位置,查询出来就变成false和true了,checkbox再也无法正常显示出来,大家帮帮忙啊,谢谢了。 import javax.swing.table.AbstractTableModel; public class SvcProviderTableModel
extends AbstractTableModel { public Vector colum;
public Vector vrow;
public SvcProviderTableModel() {
colum = new Vector();
vrow = new Vector();
colum.addElement(" "); //0
colum.addElement("title1"); //1
colum.addElement("title2"); //2
colum.addElement("title3"); //3
colum.addElement("title4"); //4
colum.addElement("title5"); //5
colum.addElement("title6"); //6
colum.addElement("title7"); //7
colum.addElement("title8"); //8
colum.addElement("title9"); //9
colum.addElement("title10"); //10
colum.addElement("title11"); //11
colum.addElement("title12"); //12
colum.addElement("title13"); //13
colum.addElement("title14"); //14
colum.addElement("title15"); //15
colum.addElement("title16"); //16
} // new methods public Vector getrowvalues() {
// get all row values return vrow;
} // public int getColumnCount() {
return colum.size();
} public int getRowCount() {
return vrow.size();
} public String getColumnName(int col) {
return colum.elementAt(col).toString();
} public Object getValueAt(int row, int col) {
try {
Vector rowData = (Vector) vrow.elementAt(row);
if (rowData != null) {
return rowData.elementAt(col);
}
return null;
}
catch (Exception e) {
return null;
}
} public void setValueAt(Object value, int row, int col) {
// get the array for the proper row
Vector v = (Vector) vrow.elementAt(row);
// replace the boolean object that changed
v.set(col, value);
} public boolean isCellEditable(int row, int col) {
if (col == 0)
return true;
else
return false;
} public Class getColumnClass(int col) {
if (col == 0)
return Boolean.class;
else
return getValueAt(0, col).getClass();
} public void addRow(Vector someVector) {
vrow.addElement(someVector);
fireTableDataChanged();
} public void removeRow() {
int count = this.getRowCount();
for (int i = 0; i < count; i++) {
vrow.removeElementAt(0);
fireTableDataChanged();
}
} public void removeRow(int row) {
vrow.removeElementAt(row);
fireTableDataChanged();
}
if (col == 0)
return Boolean.class;
else
return getValueAt(0, col).getClass();
}
这一段代码是控制编辑器的 你想把JCheckbox放在哪一列 就把col == 0改一下就好了,比如你想放在第3列,那么改成col == 2就好了