final JComboBox comboBox = new JComboBox()
groups = new ArrayList<String>()
comboBox.setEditable(true)
TableComboBoxEditor editor = new TableComboBoxEditor(comboBox)
table.getColumnModel().getColumn(2).setCellEditor(editor)
table.getModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
if (e.getType() == TableModelEvent.UPDATE &&e.getColumn() == 2) {
int lastRow = e.getLastRow()
Object value = table.getValueAt(lastRow, 2)
if (value != null &&!value.equals("") &&!groups.contains(value.toString())) {
String item = value.toString()
groups.add(item)
comboBox.addItem(item)
comboBox.setSelectedItem(item)
}
}
}
})
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
requestFocus()
}
})
关键你获取的cell对象不对,不能为component类型的对象,还有你第二种方法只是给jtable加个focus时间而已,而不是单元格时间,呵呵,好久没弄过gui了,不知道还对不对欢迎分享,转载请注明来源:内存溢出
评论列表(0条)