JTable可以给表格的某一列加入控件,下面方法可以实现
try{
TableColumn column = jTable.getColumn(colName);
column.setCellEditor(new DefaultCellEditor(new JComboBox()));
}catch(IllegalArgumentException ex){
}
或者
TableColumn column = JTable.getColumnModel().getColumn(int column);
column.setCellEditor(new DefaultCellEditor(new JComboBox()));
TableColumn column = jTable.getColumn(colName);
column.setCellEditor(new DefaultCellEditor(new JComboBox()));
}catch(IllegalArgumentException ex){
}
或者
TableColumn column = JTable.getColumnModel().getColumn(int column);
column.setCellEditor(new DefaultCellEditor(new JComboBox()));
下面这个类可以帮助我们在表格的某一个指定的单元格实现下拉列表效果
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.EventListenerList;
import javax.swing.table.TableCellEditor;
public class ComboBoxCellEditor extends JComboBox implements TableCellEditor ... {
protected EventListenerList listenerList = new EventListenerList();
protected ChangeEvent changeEvent = new ChangeEvent(this);
public ComboBoxCellEditor() ...{
super