http://www2.gol.com/users/tame/swing/examples/JTableExamples2.html
看each row editor

解决方案 »

  1.   

    the default editor of JTable is JLabel.
    I think you can set the editor is JComponent.
    then you set editor for every row
      

  2.   

    我恰好这样子做过:)基本思路就是实现TableCellEditor接口,自己写一个实现类。最重要的方法就是重载
    public abstract Component getTableCellEditorComponent (JTable table,
                                       Object value,
                                       boolean isSelected,
                                       int row,int col)
    你可以通过row或者value的不同来返回自己需要的Component作为该单元或者该value的编辑器。用同样的办法,你最好把Table的Renderer也自己写一下。保证为每种不同的对象有确切的绘制器。
    比如:
    if (row ==2){
       JCheckBox cbkEditor = new JCheckBox();
       Boolean b = (Boolean)value;//假定这一行是一个Boolean类型
       cbkEditor.setSelected(b.boolValue());
       return cbkEditor;
    }
    else{
       JComboBox enumEditor = new JComboBox();
       enmuEidtor.addItem("A");
       ...
       return enumEditor;
    }