/** * Execeliga vahetatakse mälupuhvri kaudu andmeid tekstikujul, * kus lahtreid eraldavad tabulaatorid ning ridu reavahetused. * Siinse klassi isendi saab JTable ümber kinnitada, nii et tabel * hakkab reageerima klahvikombinatsioonidele CTRL+C ja CTRL+V. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.datatransfer.*; import java.util.*; public class ExceliAdapter implements ActionListener { private String rowstring,value; private Clipboard puhver; private StringSelection stsel; private JTable tabel ; public ExceliAdapter(JTable uustabel) { tabel = uustabel; KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK,false); //klahv C, CTRL all ning klahvi ülestõstmisel ei reageeri. KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK,false); tabel.registerKeyboardAction(this,"Copy",copy,JComponent.WHEN_FOCUSED); tabel.registerKeyboardAction(this,"Paste",paste,JComponent.WHEN_FOCUSED); puhver = Toolkit.getDefaultToolkit().getSystemClipboard(); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Copy")){ StringBuffer sbf=new StringBuffer(); int veerge=tabel.getSelectedColumnCount(); int ridu=tabel.getSelectedRowCount(); int[] read=tabel.getSelectedRows(); int[] veerud=tabel.getSelectedColumns(); for (int i=0;i