Java JTable Row copyRows(JTable table)

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

Description

copy Rows

License

Open Source License

Declaration

public static void copyRows(JTable table) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.awt.Toolkit;

import java.awt.datatransfer.StringSelection;

import javax.swing.JTable;

public class Main {
    public static void copyRows(JTable table) {

        StringBuffer sb = new StringBuffer();
        for (int iSelectedRow : table.getSelectedRows()) {
            sb.append(getColumnData(table, iSelectedRow));
            sb.append("\n");
        }//  w w  w. j  a  v a2  s . c  om

        final StringSelection stsel = new StringSelection(sb.toString());
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stsel, stsel);
    }

    private static StringBuffer getColumnData(final JTable table, final int iSelectedRow) {
        final int iColumnCount = table.getColumnCount();
        final StringBuffer sb = new StringBuffer();
        for (int iColumn = 0; iColumn < iColumnCount; iColumn++) {
            sb.append(table.getValueAt(iSelectedRow, iColumn));
            sb.append("\t");
        }
        return sb;
    }
}

Related

  1. checkRow(DefaultTableModel table, List data, int row)
  2. clearAllRows(JTable table)
  3. contains(int row, TableModel model)
  4. createDBXMLFile(JTable table, String docField, String rowField, Connection con, boolean reuseConnection, String driver, String dsn, String user, String password, String tableName, String whereString, String orderByString, String groupByString, boolean convertCharsToEntites)
  5. createThrowableMessage(Throwable t)
  6. deleteRows(final int[] sortedRows, final List list, final AbstractTableModel model)
  7. ensureRowCount(int count, JTable table)