I can catch event in a custom component using processKeyEvent method like this way.

class CustomComp extends JPanel
{
   @Override
   public void processKeyEvent(final KeyEvent event)
    {
     if (event.getKeyCode() == KeyEvent.VK_DOWN)
      {
          //do somthing here
      }
   }
}

is there any alternative ways to do that?

有帮助吗?

解决方案

The preferred method would probably be to use the Key Bindings API

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top