JTable table = new JTable(); table.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { System.out.println("Key pressed: " + e.getKeyCode()); } });
JTable table = new JTable(); table.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int row = table.getSelectedRow(); int col = table.getSelectedColumn(); if (e.getKeyCode() == KeyEvent.VK_ENTER && row == 2 && col == 3) { // Perform custom action } } });This code uses the KeyListener to determine the currently selected cell in the JTable, and if the Enter key is pressed while a specific cell is selected, performs a custom action. The javax.swing JTable class is part of the Java Swing package library.