如何能得到JTable控件中的JCheckBox控件.
我在Jtable中添加了JCheckBox控件,但是希望在添加控件时,首先判断在单元格中是否有控件,如果有只是用原先的控件,如果没有就新增,所在getTableCellEditorComponent,加了一个判断,但是报错.Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
原码如下:
public class TableCellEditor_s extends JPanel implements TableCellEditor, ActionListener {
@Override
public Component getTableCellEditorComponent(JTable table, Object objValue, boolean isSelected, int iRow, int iColumn) {
if (table.getCellEditor()!=null){
TableCellEditor cellEditor=table.getCellEditor(0,1);
Component component=cellEditor.getTableCellEditorComponent(table, objValue, isSelected, 0 , 1);
//这里报错,Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
return (JCheckBox)component
}else{
if (iColumn == 1) {
JCheckBox checkBox = new JCheckBox();
checkBox.setText("a");
return checkBox;
}
}
return null;
}
}