Java JTable Model getSelectedModelIndex(JTable table)

Here you can find the source of getSelectedModelIndex(JTable table)

Description

get Selected Model Index

License

Open Source License

Declaration

public static int getSelectedModelIndex(JTable table) 

Method Source Code


//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;
    }
}

Related

  1. convertSelectionToModel(JTable table)
  2. convertTableToList(DefaultTableModel table)
  3. dumpToText(TableModel m, String filename)
  4. fireTableDataChangedAndKeepSelection(final AbstractTableModel tableModel, final JTable table)
  5. getDefaultTableModel()
  6. getTableContent(TableModel table)
  7. insertTableModelListener( TableModel model, TableModelListener l, int index)
  8. insertTableModelListener(TableModel model, TableModelListener l, int index)
  9. makeDefaultTableModel(String[] titleA, final Class[] typesA, final boolean[] canEditA)