JTable table = new JTable(); ActionMap actionMap = table.getActionMap(); actionMap.put("DELETE", new DeleteAction());
JTable table = new JTable(); ActionMap actionMap = table.getActionMap(); String copyKey = "COPY"; KeyStroke copyKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK); actionMap.put(copyKey, new AbstractAction() { public void actionPerformed(ActionEvent e) { copySelectionToClipboard(table); } }); table.getInputMap().put(copyKeyStroke, copyKey);This example creates a custom action and maps it to the "COPY" key. It also maps the CTRL+C keystroke to the "COPY" key. When the "COPY" key is pressed, the copySelectionToClipboard() method is called, which copies the selected cells in the JTable to the clipboard. This code example is using the javax.swing package library.