我在Jtalbe中有一列需要显示checkbox,现在的问题是checkbox可以显示,但是不能被勾选,isEditable()已经返回true了啊,该列的cellRenderer如下:
public class RepeatAttributeCellRenderer  implements TableCellRenderer, Serializable  {
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
            System.out.println(value.toString()+"  row="+row+"  cloumn="+column);
            Component component = null;
            SelectedAttributesTableModel model = (SelectedAttributesTableModel)table.getModel();
            JCheckBox checkBox = SubtotalCellRenderer.buildCheckBox(table, isSelected, hasFocus);
            boolean isSubTotalSelected = ((Boolean)model.getValueAt(row, column-1)).booleanValue();
            checkBox.setEnabled(isSubTotalSelected);
            checkBox.setSelected(((Boolean)value).booleanValue());
            component = checkBox;  
        return component;
    }
    
}小弟,对java GUI开发不是很熟悉,请各位高手帮忙看下,这个问题已经困扰小弟一天了,急啊!!!

解决方案 »

  1.   

    你查一下这句里
     checkBox.setEnabled(isSubTotalSelected);
     的isSubTotalSelected 值是什么,改一下试
      

  2.   

    jtable中显示checkbox不需要使用cellrenderer,直接将该列的数据类型设置为boolean就行。
      

  3.   


    class MyTableModel extends  DefaultTableModel{

    public MyTableModel(Vector data,Vector columns){
    super(data,columns);
    }
    public   boolean   isCellEditable(int   row,int   column){

            return true; }

    public Class<?> getColumnClass(int columnIndex) {

    if(columnIndex==0){ //設置第幾列是checkbox
    return Boolean.class;
    }
    return Object.class;
    }

    }