Get row by index from JTable

后端 未结 7 755
情歌与酒
情歌与酒 2021-01-07 10:32

How to get row with index i froj JTable ? I looked at member functions but there is nothing like getRowAt . Can anybody help ?

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-07 11:02

    AFAIK, there is no such method. Write something like that:

    public String[] getRowAt(int row) {
         String[] result = new String[colNumber];
    
         for (int i = 0; i < colNumber; i++) {
             result[i] = table.getModel().getValueAt(row, col);
         }
    
         return result;
    }
    

    P.S - Use table.getValueAt() if you want to respect a rearranged by the user column order.

提交回复
热议问题