我正在尝试在JComboBox
单元格中添加JTable
。
在行向量
Vector rown=new Vector();
rown.add(comboBox1);
并运行我的GUI,表格显示:
javax.swing.JComboBox[,0,0,0x0,invalid,layout=javax.swing.plaf.metal.MetalComboBoxUI$MetalComboBoxLayoutManager,alignmentX=0.0,alignmentY=0.0,border=,flags=16777536,maximumSize=,minimumSize=,preferredSize=,isEditable=false,lightWeightPopupEnabled=true,maximumRowCount=8,selectedItemReminder=VALUE_ONE
而不是VALUE_ONE
中的JComboBox
。
我哪里错了?
答案 0 :(得分:0)
TableColumn comboCol1 = table.getColumnModel().getColumn(0);
comboCol1.setCellEditor(new CustomComboBoxEditor());
public class CustomComboBoxEditor extends DefaultCellEditor {
private DefaultComboBoxModel model;
public CustomComboBoxEditor() {
super(new JComboBox());
this.model = (DefaultComboBoxModel)((JComboBox)getComponent()).getModel();
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
model.addElement(orderList.get(i));
}
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
}