Get row by index from JTable

后端 未结 7 676
情歌与酒
情歌与酒 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:23
     private void jTable1MousePressed(java.awt.event.MouseEvent evt) {                                     
    
        int selectedRow;
    
        ListSelectionModel rowSM = jTable1.getSelectionModel();
    
          rowSM.addListSelectionListener(new ListSelectionListener()
          {
            @Override
            public void valueChanged(ListSelectionEvent e) 
            {
                ListSelectionModel lsm = (ListSelectionModel) e.getSource();
    
                selectedRow = lsm.getMinSelectionIndex();
    
                int numCols = jTable1.getColumnCount();
    
                model = (DefaultTableModel) jTable1.getModel();
    
                System.out.print(" \n row " + selectedRow + ":");
    
                for (int j = 0; j < numCols; j++) 
                {
                    System.out.print(" " + model.getValueAt(selectedRow, j));
                }
    
            }
        });
    }
    

    Using this you can get value of whole row where u click on particular row.

    0 讨论(0)
提交回复
热议问题