如何能得到JTable控件中的JCheckBox控件.

Taotesea Taotesea 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

我在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;
}
}
...全文
评论 14
收藏 已收藏
分享
返回顶部
Taotesea
Java SE 62,620 成员 307,251 内容