我正在使用哈希图来填充 jtable。用户选择一行并单击编辑按钮。我从哈希图中获取值并将其放置在文本区域中。用户可以进行更改,然后单击另一个按钮。我有新的值和键,但我不确定如何将更改的值写回哈希图中的正确键。
这是我将数据写入文本区域的地方
private void outputSelection() {
StringBuffer csb = new StringBuffer();
String s = "";
int[] row = selectTable.getSelectedRows();
for(int i = row.length-1; i >= 0; i--){
String check = (String) EdiMapTableModel.getMapInstance().getValueAt(i, EdiMapTableModel.getMapInstance().COMMENT_COL);
if (!isNullOrEmpty(check)) {
if (csb.length() > 0) {
csb.append("\n");
}
csb.append(check);
}
}
s = csb.toString();
csb.setLength(0);
output.append(s);
}
这是我试图恢复价值的地方
private void inputSelection() {
String s = output.getText();
int[] row = selectTable.getSelectedRows();
for(int i = row.length-1; i >= 0; i--){
TCComponentItemRevision check = (TCComponentItemRevision) EdiMapTableModel.getMapInstance().getValueAt(i, EdiMapTableModel.getMapInstance().ITEMID_COL);
EdiMapTableModel.getMapInstance().commentBackMap(check, s);
repaint();
}
}
这是我试图把它放回地图的地方
public void commentBackMap(int row, TCComponentItemRevision id, String comment) {
if(model.containsKey(id)) {
model.put(id, comment);
}
fireTableDataChanged();
}// end commentBackMap()
我知道 containsKey 不在上面。id 是关键值
我是否需要遍历哈希图以寻找匹配项?不知道它是否重要,但它是一个linkedhashmap而不是一个hashmap