I have a JList with a key listener so that the user can remove an item from the list. On windows, this works fine. You press the delete key and the item is deleted. On mac, the program does not respond to the delete key. I use KeyEvent.VK_DELETE, and I thought it was a neutral way to detect special keys. Is there any other way to detect keystroke on Mac?
studentJList.setModel(studentListModel);
studentJList.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
studentListModel.remove(studentJList.getSelectedIndex());
studentJList.revalidate();
}
}
@Override
public void keyReleased(KeyEvent e) { }
@Override
public void keyTyped(KeyEvent e) { }
});
source
share