I created one JFrame
with JDesktopPane
, in which I am calling JInternalFrame
. Now I want to close that internal frame by pressing escape key.
I tried 2-3 ways, but no output.
I did that by using code given below:
public static void closeWindow(JInternalFrame ji){ ActionListener close=New ActionListener(){ public void actionPerformed(ActionEvent e){ ji.dispose(); } };
When I called above method from my intern frame class constructor by supplying its object , I was able to close it. But when there I write some other lines of code to the constructor. The above method call doesn't work. Please help me. I unable to find the problem in the code.
- Also I tried to add
KeyListener
to internal frame, so I able to work with key strokes,but it also doesn't work. Again I tried to
setMnemonic
to button as escape as below:jButton1.setMnemonic(KeyEvent.VK_ESCAPE);
But also gives no output.