JTable中的JComboBox

我在JTable的第3和第4列中有一个JComboBox,但我不知道如何获取它的项目…问题不是获取项目的方法,而是演员表

JComboBox combo=(JComboBox) jTable1.getColumnModel().getColumn(3).getCellEditor(); 

你能帮我吗?

JComboBox包含在CellEditor 。 您必须检索包装的组件,例如在使用DefaultCellEditor

 DefaultCellEditor editor = (DefaultCellEditor)table.getColumnModel().getColumn(3).getCellEditor(); JComboBox combo = (JComboBox)editor.getComponent(); 

阅读本教程,了解如何在JTable中使用JCombobox作为编辑器。
http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#combobox

尝试这样的事情:

  public void example(){ TableColumn tmpColum =table.getColumnModel().getColumn(1); String[] DATA = { "Data 1", "Data 2", "Data 3", "Data 4" }; JComboBox comboBox = new JComboBox(DATA); DefaultCellEditor defaultCellEditor=new DefaultCellEditor(comboBox); tmpColum.setCellEditor(defaultCellEditor); tmpColum.setCellRenderer(new CheckBoxCellRenderer(comboBox)); table.repaint(); } /** Custom class for adding elements in the JComboBox. */ class CheckBoxCellRenderer implements TableCellRenderer { JComboBox combo; public CheckBoxCellRenderer(JComboBox comboBox) { this.combo = new JComboBox(); for (int i=0; i