返回第一行后的最后一行java jtable

时间:2019-07-09 15:59:21

标签: java jtable row selection

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        System.out.println("Total Rows - " + jTable1.getRowCount());
        System.out.println("Selected Row - " + jTable1.getSelectedRow());
        //Store the value of selected row in a avariable
        int currentSelectedRow = jTable1.getSelectedRow();

        //Check if row is selected
        if (currentSelectedRow != -1) {
            //To move up substract 1 from the current selected row
            model.moveRow(currentSelectedRow, currentSelectedRow, currentSelectedRow - 1 );
            jTable1.getSelectionModel().setSelectionInterval(currentSelectedRow - 1, currentSelectedRow -1 );

//            if you reach the top row go back to the last row

            if (currentSelectedRow == 0 ) {
                currentSelectedRow = jTable1.getRowCount();
            }
        }

    }

在到达Java jtable gui应用程序的第一行后,我无法返回到最后一行。该代码位于一个按钮内,该按钮应突出显示所选行的上移方向,并在到达最后一行(第一行)时返回到最后一行。

0 个答案:

没有答案