我创建了一个从Mysql数据库检索数据并在JTable中显示它们的应用程序。然后我在第一列添加了复选框,我可以用TableCellRendere来显示它们。但当我尝试选中它们时,复选框未被选中。事实上,我在这个链接中读到了如何正确使用TableCellEditor,但我没有很好地理解:
https://docs.oracle.com/javase/8/docs/api/javax/swing/table/TableCellEditor.html
然后我得到了这段代码,但是我不知道要在public Component getTableCellEditorComponent()方法中添加什么。
下面是我需要完成的代码:
public class CheckBoxCellEditor extends AbstractCellEditor implements TableCellEditor {
protected JCheckBox checkBox;
public CheckBoxCellEditor() {
checkBox = new JCheckBox();
checkBox.setHorizontalAlignment(SwingConstants.CENTER);
}
public Component getTableCellEditorComponent(
JTable table,
Object value,
boolean isSelected,
int row,
int column) {
// What should I add here and can you explain me
return checkBox;
}
public Object getCellEditorValue() {
return Boolean.valueOf(checkBox.isSelected());
}}
谢谢
发布于 2017-06-27 05:09:54
https://stackoverflow.com/questions/44616114
复制相似问题