如何在jtable行中为多个值插入jcombobox

Hashmap包含键和值(解析XML的结果)。 Hashmap包含键是字符串的方式,值是向量。 键可以在向量中具有单个值,也可以在向量中具有多个值。 这个hashmap必须放入jtable中,这样如果键有单个值,就把它放到文本框中。 如果它有多个值,则在表格中插入一个combobox。

您可以更改代码。

hashmap.put(nodeList.item(j).getNodeName(), nodeValueList); Set keys = PropertyIMPL.hashmap.keySet(); Iterator iteratorKeys = keys.iterator(); while (iteratorKeys.hasNext()) { String key = (String) iteratorKeys.next(); if (nodeValueList.size() > 1) { tablemodel.insertRow(0, new Object[]{key}); String[] ss = (String[]) nodeValueList.toArray( new String[nodeValueList.size()]); TableColumn col = table.getColumnModel().getColumn(1); col.setCellEditor(new MyComboBoxEditor(ss)); } else { tablemodel.insertRow(0, new Object[]{key, nodeValueList}); } } keys.clear(); 

简短的回答是你需要覆盖JTable的getCellEditor(…)方法。