Example usage for javax.swing JTable convertRowIndexToModel

List of usage examples for javax.swing JTable convertRowIndexToModel

Introduction

In this page you can find the example usage for javax.swing JTable convertRowIndexToModel.

Prototype

public int convertRowIndexToModel(int viewRowIndex) 

Source Link

Document

Maps the index of the row in terms of the view to the underlying TableModel.

Usage

From source file:utils.ZTransform.java

@Override
public void actionPerformed(ActionEvent e) {
    List<CMatrix> loadedCMatrices = CoolMapMaster.getLoadedCMatrices();
    if (loadedCMatrices == null || loadedCMatrices.isEmpty()) {
        Messenger.showWarningMessage("No datasets were imported.", "No data");
        return;// w ww.j  a v  a2s .c  o m
    }

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            JTable table = new JTable();
            DefaultTableModel defaultTableModel = Utils.getDefaultTableModel();
            table.setModel(defaultTableModel);
            table.getColumnModel().removeColumn(table.getColumnModel().getColumn(0));
            table.getTableHeader().setReorderingAllowed(false);

            int returnVal = JOptionPane.showConfirmDialog(CoolMapMaster.getCMainFrame(), new JScrollPane(table),
                    "Select data", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
            if (returnVal == JOptionPane.OK_OPTION) {
                int[] selectedRows = table.getSelectedRows();
                ArrayList<CMatrix> selectedMatrices = new ArrayList<CMatrix>();
                for (int row : selectedRows) {

                    int index = table.convertRowIndexToModel(row);
                    try {
                        String ID = table.getModel().getValueAt(index, 0).toString();
                        CMatrix mx = CoolMapMaster.getCMatrixByID(ID);
                        if (mx != null) {
                            selectedMatrices.add(mx);
                        }
                    } catch (Exception e) {

                    }
                }
                //do
                createZTransform(selectedMatrices);
            }
        }
    });

}