Here you can find the source of componentListensForKey(JComponent component, int keyCode)
Parameter | Description |
---|---|
component | The component to examine. |
keyCode | The key code to test. |
static public boolean componentListensForKey(JComponent component, int keyCode)
//package com.java2s; //License from project: Open Source License import javax.swing.*; public class Main { /**//w ww . j ava 2s. co m * Returns whether a component listens for a key code, i.e. it has an * action associated with the key code. * @param component The component to examine. * @param keyCode The key code to test. * @return True if the component listens for the key code, false otherwise. */ static public boolean componentListensForKey(JComponent component, int keyCode) { KeyStroke[] keyStrokes = component.getInputMap().allKeys(); if (keyStrokes == null) return false; for (int i = keyStrokes.length - 1; i >= 0; i--) { if (keyCode == keyStrokes[i].getKeyCode()) { return true; } } return false; } }