0

我正在使用 JTable。假设我有一个包含以下信息的表 -

        col1     col2    col3    col4
row1    ---      value1   ---    ---
row2    ---      value2   ---    ---
row3    ---      value3   ---    ---
row4    ---      value3   ---    ---
row5    ---      value1   ---    ---
row6    ---      value1   ---    ---
row7    ---      value2   ---    ---
row8    ---      value1   ---    ---

我需要将 col2 值为“value1”的行复制到另一个表中。有人可以帮我解决这个问题吗?

4

1 回答 1

0

我假设你的意思是在你的程序中。

int rowCount = table.getRowCount();
int columnCount = table.getColumnCount();
int row = 0; 

for (int i = 0; i < rowCount; i++) {
    String value = table.getValueAt(i, 2);
    if (value.equals("value2") {
        for (int j = 0; j < columnCount; j++) {
            value = table.getValueAt(i, j);
            newTable.setValueAt(value, row, j): 
        }
        row++;
    }
}
于 2012-07-25T19:36:31.350 回答