[英]I am trying to add A JComboBox in a JTable Cell,
我正在尝试在JTable
单元中添加JComboBox
。 在行向量中添加JComboBox之后
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
而不是JComboBox
VALUE_ONE
。
我哪里错了?
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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.