here is my code, i basically just did a tester for the most common listeners, which i might later use in future projects, the main problem is in the keylistener at the bottom, i
Visible components can have the keyboard focus, and recieve keyboard and other input events, but invisible components cannot have the focus, nor recieve input events. When you make the frame invisible, it stops recieving input events, as does all it's children, including the test
component you are adding a KeyListener
to.
To make this work, you will have to have a visible component, and forward keyboard events from that to your invisible frame. Or better, call invisibelFrame.setVisible(true)
from your already visible component.
Alternatively, you may be able to find some other way to trigger showing the frame. For example, a system tray component, with a context menu is a common pattern for hiding and showing application frames (and for some users, causing much chagrin in the process!)
See
Yes it is possible but you will need to use a external java library with a native library. Search for "JIntellitype". But this will only work on Windows. If you want to use this functionality on linux, use "JXGrabKey"
As a general rule you should NOT be using a KeyListener. That was the old way of doing things when only AWT was around.
When using Swing you should be using Key Bindings. The binding won't solve your problem with invisible components and frames but this is approach all Swing component use.