Hashmap 包含键和值(解析 XML 的结果)。 Hashmap 以键是字符串、值是 vector 的方式包含事物。 键可以在 vector 中具有单个值或在 vector 中具有多个值。 该 HashMap 必须放入 jtable 中,这样如果键具有单个值,则将其放入文本框。如果它有多个值,请在表中插入一个组合框。
您可以更改代码。
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(...) 方法。
关于java - 如何在 jtable 行中插入 jcombobox 以获得多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6026474/