/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package clases;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author chuen
 */
public class copiar_tabla {

public void copiartabla(DefaultTableModel modelo){
    StringSelection stsel;
Clipboard system;
StringBuffer sbf=new StringBuffer();
int numcols=modelo.getColumnCount();
int numrows=modelo.getRowCount();

 for (int i=0;i<numrows;i++)
            {
               for (int j=0;j<numcols;j++)
               {
sbf.append(modelo.getValueAt(i,j));
                  if (j<numcols-1) sbf.append("\t");
               }
               sbf.append("\n");
            }
 stsel  = new StringSelection(sbf.toString());
            system = Toolkit.getDefaultToolkit().getSystemClipboard();
            system.setContents(stsel,stsel);

    JOptionPane.showMessageDialog(null, "Se ha copiado la tabla a su portapapeles. \nPuede pegarla en otro documento pulsando CTRL+V");
    
}
}
