在jtable中添加JComboBox控件
新建JComboBox对象,从jtable中得到列对象TableColumn,给此列设置JComboBox
javax.swing.JComboBox cbox1 = new JComboBox();
cbox1.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
itemChanged(e); // comboBox某项被选中
}
});
TableColumn tc0 = this.jTable1.getColumnModel().getColumn(0);
tc0.setCellEditor(new DefaultCellEditor(cbox1));
DefaultComboBoxModel cbm =(DefaultComboBoxModel) cbox1.getModel();
for (Map row:sheetPrice){
Integer id = 1;
String type = "type";
cbm.addElement(new u_sheet(id,type));
}
u_sheet 是一个子定义的class
class u_sheet{
private Integer id;
private String type;
public u_sheet(Integer id, String type) {
this.id = id;
this.type = type;
}
@Override
public String toString() { // 这句重要
return this.type;
}
}
阅读(1936) | 评论(0) | 转发(0) |