建议你看看java tutorial,里面关于JTable的教程有现成的例子,都是你需要的。

解决方案 »

  1.   

    请问:哪里有java tutorial?
      

  2.   

    table对象.getColumnModel().getColumn(n).setCellEditor
    (new DefaultCellEditor(new JComboBox(vector对象)));
      

  3.   

    http://java.sun.com/docs/books/tutorial/information/download.html
      

  4.   

    你需要写一个类来实现TableCellEditor接口,使用DefaultCellEditor只能做到给一列加一个统一的编辑的东东。
    当时我的需要是在同一列中也要根据不同的情况产生不同的编辑器(有的是下拉框,有的是文本框)。你首先看你的具体需求,如果只是我说的第一种情况,用DefaultCellEditor即可,Tutorial上不是有源文件的链接吗?你可以打开,看一下,如果是跟我的情况相同,我可以给你一段代码:
    我是用内部类实现的,你可以参考。
    /**
    * this inner class implement interface of TableCellEditor 
    * mainly make user select instance-value
    */
    class MyDefaultTableEditor extends AbstractCellEditor implements TableCellEditor{
    private JComboBox jcb_instance = null;
    private JTextField jtf_instance = null;
    private String propertyName = null;

    //identify if property is relative,use different Get-Value-Method
    private boolean isRelative = false;

    public MyDefaultTableEditor(){
    jcb_instance = new JComboBox();
    jtf_instance = new JTextField();
    }
         public Object getCellEditorValue(){
         Object returnVal = null;
         if (isRelative){
        returnVal = jcb_instance.getSelectedItem();
        jcb_instance.removeAllItems();
    }
    else{
    returnVal = jtf_instance.getText();
    jtf_instance.setText("");
    }
    return returnVal;
         } 
        
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column){
         //get property name
         propertyName = (String)jtable_instanceValue.getValueAt(row,0);
        
         //if property is relative,find instances of specific class
         SMALProperty eProperty = model.getEachProperty(propertyName);
         if ( (eProperty!=null) && (eProperty.getRelative()) ){
         isRelative = true;
    //fill combobox data
    String className = eProperty.getRange();
    Object[] instances = model.getInstances(className,true);     
    jcb_instance.removeAllItems();
    for (int i=0; i<instances.length; i++) {
    jcb_instance.addItem(instances[i]);
        }
        return jcb_instance;
         }
         else{
         isRelative = false;
         jtf_instance.setText((String)value);
            }
         return jtf_instance;    
        }
    }
      

  5.   

    staminalim(舵手) 的果然不错。
      

  6.   

    staminalim,你能不能给个完整的例子啊,谢谢!
      

  7.   

    自己去下API吧,里头有好多源程序,挺好的,免得需要的时候又到处找