Here you can find the source of getSelectedModelIndex(JTable table)
public static int getSelectedModelIndex(JTable table)
//package com.java2s; //License from project: Open Source License import javax.swing.*; public class Main { public static int getSelectedModelIndex(JTable table) { int selectedRow = table.getSelectedRow(); if (selectedRow < 0) { return -1; }//from w w w.ja v a 2 s . c o m return rowToModelIndex(table, selectedRow); } public static int rowToModelIndex(JTable table, int row) { if (row >= 0) { RowSorter<?> rowSorter = table.getRowSorter(); return rowSorter != null ? rowSorter.convertRowIndexToModel(row) : row; } return -1; } }